
* ====================================================
* Project: MOTIVATED BELIEFS ABOUT STOCK RETURNS
* Purpose: Reproduce all figures, tables and tests of Study 2
* Author: Carlos Cueva & Iñigo Iturbe-Ormaetxe
* Date: 2025-04-10
* Stata Version: 16
* ====================================================

*THIS DO FILE CONTAINS THE CODE TO BUILD ALL FIGURES, TABLES AND TESTS OF STUDY 2

* ====================================================
* 1. Clear environment
* ====================================================
clear all

* ====================================================
* 2. Set path & load data
* ====================================================

cd "your_pathname"

use Study_2_Data.dta

exit

*Needed package for Fig 5:
ssc install grc1leg2

* ====================================================
* 3. Description of variables in the dataset
* ====================================================

*id: individual identifier, takes values from 1,111 different values
*day: takes values {1,2,..,42}. Day 1 - Oct 13th 2020 (start day), ..., day 21 - Nov 2nd 2020 (treatment day), ..., day 42 - Nov 23rd 2020 (end day)
*week: takes values {1,2,3,4,5,6,7}
*stock: takes values {1,2,3,4,5,6}. 1 = Alibaba, 2 = Facebook, 3 = Netflix, 4 = Tesla, 5 = Uber, 6 = Zoom
*price: stock price
*predprice: prediction (i) (point estimate)
*predprob: prediction (iii) (subjective probability of positive return)
*predmin, predmax: prediction (ii) (95% confidence interval)
*owned: takes value 1 if stock is eventually owned, 0 otherwise
*treament: takes values {0,1,2}. 0 = Baseline, 1 = Choice, 2 = Ownership
*stockgroup: takes values {1,2,3}. 1 = Losers, 2 = Neutral, 3 = Winners
*endprice = closing price on 31/12/2020
*post = 0 if pre-treatment, = 1 if post-treatment
*target = 1 if hypothetically chosen in treatment 0 or if owned in treatment 1 or if hypothetically chosen and owned in treatment 2
*pred_norm = (predprice - price)/price
*price_buy = purchase price on treatment day.
*finlit: numbers of correct question in the financial literacy test. From 0 to 3.
*high_fin_crt = 1 if (crt + finlit)/6 > 0.67 (median)
*will_invest = 1 if “probably”, “most likely” or “definitely” will invest in the future
*expert = 1 if 3rd or 4th year students, = 0 if 1st year students
*experienced = 1 if experience investing = "a little", "some" or "a lot".
*sell = 1 if sells the stock on day 42 in treatments 1 and 2
*buy = 1 if buys the stock on day 42 in treatment 0
*numpreds: total days of predictions by each subject, from 0 to 30.
*numpreds_pre: total days of predictions before treatment, from 0 to 15.
*numpreds_post: total days of predictions after treatment, from 0 to 15.
*idstock: all combinatios id*stock
*screen_time_secs_portfolio: identifies subjects who did not complete the final stage

* ====================================================
* 4. Figures and tables in the main text
* ====================================================

*****************************************************************************************************************************
*************   Table 2 in the main text: Mean Predictions, Volatility and Returns of Stocks in Study 2     *****************
*****************************************************************************************************************************

preserve

collapse price endprice predprice predprob predmin predmax price_buy, by(day stock)
sort stock day

gen startprice = price if day==1
by stock: replace startprice = startprice[1] if day>1
replace startprice=. if price==.
gen day21price = price if day==21
by stock: replace day21price = day21price[21] if day!=21
replace day21price=. if price==.
gen return = (price - day21price)/day21price if day>21 
by stock: egen stdev = sd(price)

table stock, c(mean predprice mean predmin mean predmax) 
table stock, c(mean predprob mean endprice mean return)

*Volatility data obtained from Yahoo Finance.

restore


*****************************************************************************************************************************
******************         Figure 3: Panel A in the main text: Daily prices and predictions in Study 2           ************
*****************************************************************************************************************************

preserve
collapse price predprice predmin predmax endprice, by(day stock)
sort stock day
grstyle init
grstyle set plain
	twoway ///
	(line price day) (line predprice day, lp(dash)) ///
	(line predmin day, lp(dot) lcolor(maroon)) (line predmax day, lp(dot) lcolor(maroon)) if stock==1, ///
	title("") xline(21) ytitle("Alibaba", size(large)) yline(232.73, lp(dash_dot) extend) ylab(225(50)350) ///
	legend(size(small) rows(1) region(lwidth(none)) order (1 2 3) label(1 "Price") label(2 "Point Prediction") label(3 "90% C.I. Prediction")) ///
	name(Alibaba, replace)
	
		twoway ///
	(line price day) (line predprice day, lp(dash)) ///
	(line predmin day, lp(dot) lcolor(maroon)) (line predmax day, lp(dot) lcolor(maroon)) if stock==2, ///
	title("Neutral") xtitle("") ytitle("Facebook", size(large)) xline(21) yline(273.16, lp(dash_dot) extend) /*ylab(225(50)350)*/ ///
	legend(order (1 2 3) label(1 "Price") label(2 "Point Prediction") label(3 "90% C.I. Prediction")) ///
	name(Facebook, replace)
	
		twoway ///
	(line price day) (line predprice day, lp(dash)) ///
	(line predmin day, lp(dot) lcolor(maroon)) (line predmax day, lp(dot) lcolor(maroon)) if stock==3, ///
	title("") xline(21) ytitle("Netflix", size(large)) yline(540.73, lp(dash_dot) extend) /*ylab(320(100)630)*/  ///
	legend(order (1 2 3) label(1 "Price") label(2 "Point Prediction") label(3 "90% C.I. Prediction")) ///
	name(Netflix, replace)
	
		twoway ///
	(line price day) (line predprice day, lp(dash)) ///
	(line predmin day, lp(dot) lcolor(maroon)) (line predmax day, lp(dot) lcolor(maroon)) if stock==4, ///
	title("") xline(21) ytitle("Tesla", size(large)) /*yline(705.67, lp(dash_dot) extend)*/ /*ylab(225(50)350)*/ ///
	legend(order (1 2 3) label(1 "Price") label(2 "Point Prediction") label(3 "90% C.I. Prediction")) ///
	name(Tesla, replace)
	
			twoway ///
	(line price day) (line predprice day, lp(dash)) ///
	(line predmin day, lp(dot) lcolor(maroon)) (line predmax day, lp(dot) lcolor(maroon)) if stock==5, ///
	title("Winners") xtitle("") ytitle("Uber", size(large)) xline(21) yline(51, lp(dash_dot) extend) ylab(30(10)55) ///
	legend(order (1 2 3) label(1 "Price") label(2 "Point Prediction") label(3 "90% C.I. Prediction")) ///
	name(Uber, replace)
	
		twoway ///
	(line price day) (line predprice day, lp(dash)) ///
	(line predmin day, lp(dot) lcolor(maroon)) (line predmax day, lp(dot) lcolor(maroon)) if stock==6, ///
	title("Losers") xtitle("") ytitle("Zoom", size(large)) xline(21) yline(337.32, lp(dash_dot) extend) ylab(325(100)600) ///
	legend(order (1 2 3) label(1 "Price") label(2 "Point Prediction") label(3 "90% C.I. Prediction")) ///
	name(Zoom, replace)
	
	grc1leg Uber Facebook Zoom Tesla Netflix Alibaba, graphregion(margin(zero)) imargin(tiny) legendfrom(Alibaba) rows(2) ///
    title("PANEL A: Mean daily prices and predictions", size(medium) margin(medium)) ///
    span /*iscale(.6)*/ name(ABC_predprice_1, replace) 
	
	graph save ABC_predprice_1, replace

restore


*Pre-post summary:
preserve
collapse pred_norm predprob, by(id treatment post owned stockgroup)
collapse pred_norm predprob, by(treatment post owned stockgroup)
*Losers Before:
sum pred_norm if stockgroup==1&owned==0&treatment==0&post==0
bys treatment: sum pred_norm if stockgroup==1&owned==1&post==0
*Losers After:
sum pred_norm if stockgroup==1&owned==0&treatment==0&post==1
bys treatment: sum pred_norm if stockgroup==1&owned==1&post==1
restore


*****************************************************************************************************************************
*******   Figure 3: Panel B in the main text: Daily mean price predictions by treatment in Study 2, using pred_norm  ********
*****************************************************************************************************************************

preserve
drop numpreds numpreds_pre numpreds_post
bys id stock post: egen numpreds = count(predprice) if predprice!=.
by id stock: egen minpreds = min(numpreds)
*bys stock: tab minpreds

drop if owned==0&treatment>0
*keep if minpreds>=5

collapse (mean) pred_norm purchase_price price, by(day stock treatment)
sort stock day

*Identify weekends:
gen weekend = 0
replace weekend = 1 if (day==5|day==6|day==12|day==13|day==19|day==20|day==26|day==27|day==33|day==34|day==40|day==41)

*Clean missing obs:
drop if treatment==. & price==. & weekend==0

*Fill weekend prices:
bys stock: replace price = price[_n-1] if price==.

*Price on day 21:
gen day21price = price if day==21
bys stock treatment (day21price): replace day21price = day21price[_n-1] if day!=21

*Fill weekends:
sort stock day
by stock: replace day21price = day21price[_n-1] if day!=21

gen temp = (price-day21price)/day21price

bys stock day: egen depreciation = mean(temp)
replace depreciation = 0 if day<= 21

*For the light shaded areas:
gen below_purchase = 0
replace below_purchase = 1 if depreciation < 0 & depreciation > -.055
*This is so that the bar height matches ymax in the graph
replace below_purchase = below_purchase*0.12 if stock !=6
replace below_purchase = below_purchase*0.14 if stock ==6

*Bottom part
gen bottom_below_purchase = 0
replace bottom_below_purchase = 1 if depreciation < 0 & depreciation > -.055
*This is so that the bar height matches ymin in the graph
replace bottom_below_purchase = bottom_below_purchase*(-0.04)

*For the dark shaded areas:
gen very_below_purchase = 0
replace very_below_purchase = 1 if depreciation < -.055
*This is so that the bar height matches ymax in the graph
replace very_below_purchase = very_below_purchase*0.12 if stock !=6
replace very_below_purchase = very_below_purchase*0.14 if stock ==6
*Bottom part
gen bottom_very_below_purchase = 0
replace bottom_very_below_purchase = 1 if depreciation < -.055
*This is so that the bar height matches ymin in the graph
replace bottom_very_below_purchase = bottom_very_below_purchase*(-0.04)

*Keep only the first obs of each day and stock (for gray bars)
bys stock day: replace below_purchase=. if _n>1
bys stock day: replace bottom_below_purchase=. if _n>1
bys stock day: replace very_below_purchase=. if _n>1
bys stock day: replace bottom_very_below_purchase=. if _n>1

sort stock day
grstyle init
grstyle set plain
	twoway ///
	(bar below_purchase day, color(black%10) lc(none) barwidth(1) )  ///
	(bar bottom_below_purchase day, color(black%10) lc(none) barwidth(1) )  ///
	(bar very_below_purchase day, color(black%30) lc(none) barwidth(1) )  ///
	(bar bottom_very_below_purchase day, color(black%30) lc(none) barwidth(1) )  ///
	(line pred_norm day if treatment==0, lp(shortdash) lcolor(green)) ///
	(line pred_norm day if treatment==1, lcolor(cranberry)) ///
	(line pred_norm day if treatment==2, lp(dash) lcolor(midblue)) ///
	if stock==1, ytitle("") ///
	title("") xline(21) ytitle("Alibaba", size(large)) ylab(-0.04(0.04)0.12)  ///
	legend(size(small) rows(2) region(lwidth(none)) order (5 6 7 1 3) ///
	label(5 "Baseline") label(6 "Choice") label(7 "Ownership") label(1 "1-5% depreciation") label(3 "6-17% depreciation")) ///
	name(Alibaba_1, replace)

	
	twoway ///
	(line pred_norm day if treatment==0, lp(shortdash) lcolor(green)) ///
	(line pred_norm day if treatment==1, lcolor(cranberry)) ///
	(line pred_norm day if treatment==2, lp(dash) lcolor(midblue)) ///
	if stock==2, ytitle("Facebook", size(large)) ///
	title("Neutral") xtitle("") xline(21) ylab(-0.04(0.04)0.12) ///
	name(Facebook_1, replace)
	
	twoway ///
	(bar below_purchase day, color(gs13) lc(none))  ///
	(bar bottom_below_purchase day, color(gs13) lc(none) barwidth(1.1) )  ///
	(line pred_norm day if treatment==0, lp(shortdash) lcolor(green)) ///
	(line pred_norm day if treatment==1, lcolor(cranberry)) ///
	(line pred_norm day if treatment==2, lp(dash) lcolor(midblue)) ///
	if stock==3, ytitle("Netflix", size(large)) ///
	title("") xline(21) ylab(-0.04(0.04)0.12) ///
	name(Netflix_1, replace)
	
	twoway ///
	(line pred_norm day if treatment==0, lp(shortdash) lcolor(green)) ///
	(line pred_norm day if treatment==1, lcolor(cranberry)) ///
	(line pred_norm day if treatment==2, lp(dash) lcolor(midblue)) ///
	if stock==4, ytitle("Tesla", size(large)) ///
	title("") xline(21) ylab(-0.04(0.04)0.12) ///
	name(Tesla_1, replace)
	
	twoway ///
	(line pred_norm day if treatment==0, lp(shortdash) lcolor(green)) ///
	(line pred_norm day if treatment==1, lcolor(cranberry)) ///
	(line pred_norm day if treatment==2, lp(dash) lcolor(midblue)) ///
	if stock==5, ytitle("") ///
	title("Winners") xtitle("") ytitle("Uber", size(large)) xline(21) ylab(-0.04(0.04)0.12) ///
	name(Uber_1, replace)
	
	twoway ///
	(bar below_purchase day, color(black%10) lc(none) barwidth(1) )  ///
	(bar bottom_below_purchase day, color(black%10) lc(none) barwidth(1) )  ///
	(bar very_below_purchase day, color(black%30) lc(none) barwidth(1) )  ///
	(bar bottom_very_below_purchase day, color(black%30) lc(none) barwidth(1) )  ///
	(line pred_norm day if treatment==0, lp(shortdash) lcolor(green)) ///
	(line pred_norm day if treatment==1, lcolor(cranberry)) ///
	(line pred_norm day if treatment==2, lp(dash) lcolor(midblue)) ///
	if stock==6, ytitle("Zoom", size(large)) ///
	title("Losers") xtitle("") xline(21) ylab(-0.04(0.04)0.12) ///
	name(Zoom_1, replace)
	
	
	*grc1leg Alibaba_1 Facebook_1 Netflix_1 Tesla_1 Uber_1 Zoom_1, legendfrom(Alibaba_1) span iscale(.6) name(ABC_predprice_2, replace)
	*grc1leg Alibaba_1 Zoom_1 Facebook_1 Netflix_1 Tesla_1 Uber_1, legendfrom(Alibaba_1) rows(3) span iscale(.6) name(ABC_predprice_2, replace)
	grc1leg Uber_1 Facebook_1 Zoom_1 Tesla_1 Netflix_1 Alibaba_1, legendfrom(Alibaba_1) rows(2) ///
	graphregion(margin(zero)) imargin(tiny) ///
    title("PANEL B: Mean daily predicted returns by treatment", size(medium) margin(medium)) ///
    span name(ABC_predprice_2, replace) 
	
	graph save ABC_predprice_2, replace

restore

graph combine ABC_predprice_1.gph ABC_predprice_2.gph, rows(2) ysize(10) xsize(7) 


*****************************************************************************************************************************
****************       Table 3 in the main text: Treatment effects on predicted returns in Study 2        *******************
*****************************************************************************************************************************

*ALL STOCKS TOGETHER
preserve
replace pred_norm = 100*pred_norm
reghdfe pred_norm i.owned##i.post##i.treatment, absorb(stock#day idstock) cluster(id) 
outreg2 using Reg_online, adjr2 excel ctitle(All) stats(coef se) dec(3) replace
*Diff-in-diff Choice vs Baseline:
lincom (_b[1.post#1.owned] + _b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment])
*Diff-in-diff Ownership vs Baseline:
lincom (_b[1.post#2.treatment] + _b[1.post#1.owned])
*Diff-in-diff Choice vs Ownership:
lincom (_b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment] - (_b[1.post#2.treatment]))
restore

*ONLY WINNERS (UBER, TESLA)
preserve
keep if stockgroup==3
replace pred_norm = 100*pred_norm
reghdfe pred_norm i.owned##i.post##i.treatment, absorb(stock#day idstock) cluster(id) 
outreg2 using Reg_online,  adjr2 excel ctitle(Winners) stats(coef se) dec(3) append
*Diff-in-diff Choice vs Baseline:
lincom (_b[1.post#1.owned] + _b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment])
*Diff-in-diff Ownership vs Baseline:
lincom (_b[1.post#2.treatment] + _b[1.post#1.owned])
*Diff-in-diff Choice vs Ownership:
lincom (_b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment] - (_b[1.post#2.treatment]))
restore

*ONLY NEUTRAL (FACEBOOK, NETFLIX)
preserve
keep if stockgroup==2
replace pred_norm = 100*pred_norm
reghdfe pred_norm i.owned##i.post##i.treatment, absorb(stock#day idstock) cluster(id)
outreg2 using Reg_online, adjr2 excel ctitle(Neutral) stats(coef se) dec(3) append
*Diff-in-diff Choice vs Baseline:
lincom (_b[1.post#1.owned] + _b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment])
*Diff-in-diff Ownership vs Baseline:
lincom (_b[1.post#2.treatment] + _b[1.post#1.owned])
*Diff-in-diff Choice vs Ownership:
lincom (_b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment] - (_b[1.post#2.treatment]))
restore

*ONLY LOSERS (ZOOM, ALIBABA)
preserve
keep if stockgroup==1
replace pred_norm = 100*pred_norm
sum pred_norm if post==0
reghdfe pred_norm i.owned##i.post##i.treatment, absorb(stock#day idstock) cluster(id) coeflegend
outreg2 using Reg_online, adjr2 excel ctitle(Losers) stats(coef se) dec(3) append
*Diff-in-diff Choice vs Baseline:
lincom (_b[1.post#1.owned] + _b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment])
*Diff-in-diff Ownership vs Baseline:
lincom (_b[1.post#2.treatment] + _b[1.post#1.owned])
*Diff-in-diff Choice vs Ownership:
lincom (_b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment] - (_b[1.post#2.treatment]))
restore


*****************************************************************************************************************************
***************     Table 4 (bottom panel) in the main text and Table E.3 in the Internet Appendix      *********************
***************                Treatment effects conditioning on target stocks                          *********************
*****************************************************************************************************************************

*ALL STOCKS TOGETHER
preserve
replace pred_norm = 100*pred_norm
reghdfe pred_norm i.post##i.treatment##i.target, absorb(stock#day idstock) cluster(id)
outreg2 using Reg_online_T, adjr2 excel ctitle(All) stats(coef se) dec(3) replace
*Diff-in-diff Choice vs Baseline:
lincom ( _b[1.post#1.treatment] + _b[1.target#1.post#1.treatment] )
*Diff-in-diff Ownership vs Baseline:
lincom (_b[1.post#2.treatment] + _b[1.target#1.post#2.treatment])
*Diff-in-diff Choice vs Ownership:
lincom ( _b[1.post#1.treatment] + _b[1.target#1.post#1.treatment] - _b[1.post#2.treatment] - _b[1.target#1.post#2.treatment] )
restore

*ONLY WINNERS (UBER, TESLA)
preserve
keep if stockgroup==3
replace pred_norm = 100*pred_norm
reghdfe pred_norm i.post##i.treatment##i.target, absorb(stock#day idstock) cluster(id)
outreg2 using Reg_online_T, adjr2 excel ctitle(Winners) stats(coef se) dec(3) append
*Diff-in-diff Choice vs Baseline:
lincom ( _b[1.post#1.treatment] + _b[1.target#1.post#1.treatment] )
*Diff-in-diff Ownership vs Baseline:
lincom (_b[1.post#2.treatment] + _b[1.target#1.post#2.treatment])
*Diff-in-diff Choice vs Ownership:
lincom ( _b[1.post#1.treatment] + _b[1.target#1.post#1.treatment] - _b[1.post#2.treatment] - _b[1.target#1.post#2.treatment] )
restore

*ONLY NEUTRAL (FACEBOOK, NETFLIX)
preserve
keep if stockgroup==2
replace pred_norm = 100*pred_norm
reghdfe pred_norm i.post##i.treatment##i.target, absorb(stock#day idstock) cluster(id)
outreg2 using Reg_online_T, adjr2 excel ctitle(Neutral) stats(coef se) dec(3) append
*Diff-in-diff Choice vs Baseline:
lincom ( _b[1.post#1.treatment] + _b[1.target#1.post#1.treatment] )
*Diff-in-diff Ownership vs Baseline:
lincom (_b[1.post#2.treatment] + _b[1.target#1.post#2.treatment])
*Diff-in-diff Choice vs Ownership:
lincom ( _b[1.post#1.treatment] + _b[1.target#1.post#1.treatment] - _b[1.post#2.treatment] - _b[1.target#1.post#2.treatment] )
restore

*ONLY LOSERS (ZOOM, ALIBABA)
preserve
keep if stockgroup==1
replace pred_norm = 100*pred_norm
reghdfe pred_norm i.post##i.treatment##i.target, absorb(stock#day idstock) cluster(id)
outreg2 using Reg_online_T, adjr2 excel ctitle(Losers) stats(coef se) dec(3) append
*Diff-in-diff Choice vs Baseline:
lincom ( _b[1.post#1.treatment] + _b[1.target#1.post#1.treatment] )
*Diff-in-diff Ownership vs Baseline:
lincom (_b[1.post#2.treatment] + _b[1.target#1.post#2.treatment])
*Diff-in-diff Choice vs Ownership:
lincom ( _b[1.post#1.treatment] + _b[1.target#1.post#1.treatment] - _b[1.post#2.treatment] - _b[1.target#1.post#2.treatment] )
restore


*****************************************************************************************************************************
*******************          Figure 4 in the main text & Table E4 in the Internet Appendix            ***********************
*******************    Treatment effects on predicted returns for each stock and week in Study 2        *********************
*****************************************************************************************************************************

*****************************************************************************************************************************
*******************                          Figure 4 in the main text                               ************************
*****************************************************************************************************************************

preserve
*week-stock interaction effects:
*set week=0 for the day of the prediction:
replace week=0 if post==0 & week==4
*NEW:
replace week=0 if week==3 & day==18
*drop week 7 (very few observations from late subjects)
drop if week==7
gen return = (price - purchase_price)/purchase_price
table week stock if treatment>0, c(mean return)
reghdfe pred_norm i.week##i.stock##i.treatment##i.owned, absorb(stock#day idstock) cluster(id) coeflegend
*Now compute stock by stock diff-in-diff: 
*week1-week0, week2-week0, week3-week0 week4-week0, week5-week0, week6-week0
restore

* Create an empty dataset to store results
clear
set obs 0  // Create an empty dataset with zero observations
gen test = "."
gen t = .
gen week = .  // Initialize a placeholder variable for week
gen stock = .  // Initialize a placeholder variable for stock
gen coef = .  // Placeholder for coefficients
gen se = .  // Placeholder for standard errors
tempfile results
save `results'

* Define the stocks and weeks
local stocks 1 2 3 4 5 6  
local weeks 1 2 3 4 5 6

* Loop through stocks and weeks
foreach stock of local stocks {
    foreach week of local weeks {
	********************
	*Choice vs Baseline:
        * Run the lincom command for the given stock and week
		lincom 100*(_b[`week'.week#1.treatment] + _b[`week'.week#1.owned] + _b[`week'.week#`stock'.stock#1.treatment] + _b[`week'.week#`stock'.stock#1.owned] + _b[`week'.week#1.treatment#1.owned] + _b[`week'.week#`stock'.stock#1.treatment#1.owned])
        * Check if lincom ran successfully
        if _rc == 0 {
            * Capture the coefficient and standard error from lincom
            local coef = r(estimate)
            local se = r(se)

            * Load the results dataset
            use `results', clear

            * Add a new observation
            set obs `=_N + 1'   // Increase the number of observations

            * Assign values directly to the new row
			replace test = "Choice v Baseline" if _n == _N
            replace t = `week' - .1 if _n == _N
            replace week = `week' if _n == _N
            replace stock = `stock' if _n == _N
            replace coef = `coef' if _n == _N
            replace se = `se' if _n == _N
		}
	********************
	*Ownership vs Baseline:
        * Run the lincom command for the given stock and week
		lincom 100*(_b[`week'.week#2.treatment] + _b[`week'.week#1.owned] + _b[`week'.week#`stock'.stock#2.treatment] + _b[`week'.week#`stock'.stock#1.owned] + _b[`week'.week#2.treatment#1.owned] + _b[`week'.week#`stock'.stock#2.treatment#1.owned])
        * Check if lincom ran successfully
        if _rc == 0 {
            * Capture the coefficient and standard error from lincom
            local coef = r(estimate)
            local se = r(se)
			
            * Add a new observation
            set obs `=_N + 1'   // Increase the number of observations

            * Assign values directly to the new row
			replace test = "Ownerhip v Baseline" if _n == _N
            replace t = `week' + .1 if _n == _N
            replace week = `week' if _n == _N
            replace stock = `stock' if _n == _N
            replace coef = `coef' if _n == _N
            replace se = `se' if _n == _N
			
            * Save the updated results back
            save `results', replace
        } 
        else {
            display "Warning: lincom failed for stock `stock' and week `week'."
        }
    }
}

* Load the final dataset
use `results', clear
list

gen ch = coef + 1.96*se
gen cl = coef - 1.96*se
grstyle init
grstyle set plain

gen max = 6
gen min = -4

gen very_below_purchase = max if stock==1 & week>=5
replace very_below_purchase = max if stock==6 & week>=5

gen bottom_very_below_purchase = min if stock==1 & week>=5
replace bottom_very_below_purchase = min if stock==6 & week>=5

gen below_purchase = max if stock==1 & week==4
gen bottom_below_purchase = min if stock==1 & week==4

*Keep only the first obs of each day and stock (for gray bars)
bys stock week: replace below_purchase=. if _n>1
bys stock week: replace bottom_below_purchase=. if _n>1
bys stock week: replace very_below_purchase=. if _n>1
bys stock week: replace bottom_very_below_purchase=. if _n>1

preserve
keep if stock==1
twoway ///
(bar below_purchase week, color(black%10) lc(none) barwidth(1) ) /// 
(bar very_below_purchase week, color(black%30) lc(none) barwidth(1))  /// 
(bar bottom_below_purchase week, color(black%10) lc(none) barwidth(1) ) /// 
(bar bottom_very_below_purchase week, color(black%30) lc(none) barwidth(1) )  /// 
(rcap ch cl t if test=="Choice v Baseline", lcolor(cranberry) lw(medium)) ///
(rcap ch cl t if test=="Ownerhip v Baseline", lcolor(midblue) lw(medium)) ///
(scatter coef t if test=="Choice v Baseline", lcolor(cranberry) m(O) mcolor(cranberry) lp(dot)) ///
(scatter coef t if test=="Ownerhip v Baseline", lcolor(midblue) m(T) mcolor(midblue) lp(dot)), ///
xlabel(1 2 3 4 5 6) yline(0, lp(dash) lcolor(black) extend) xline(3.5) ///
legend(size(*.7) rows(2) region(lwidth(none)) order (3 7 4 8) ///
	label(3 "1-5% depreciation") label(4 "6-17% depreciation") label(7 "Choice v Baseline") label(8 "Ownerhip v Baseline")) ///
xtitle("") ytitle("Alibaba", size(large)) ///
title("") name(Alibaba, replace)
restore

preserve
keep if stock==6
twoway ///
(bar very_below_purchase week, color(black%30) lc(none) barwidth(1))  /// 
(bar bottom_very_below_purchase week, color(black%30) lc(none) barwidth(1) )  /// 
(rcap ch cl t if test=="Choice v Baseline", lcolor(cranberry) lw(medium)) ///
(rcap ch cl t if test=="Ownerhip v Baseline", lcolor(midblue) lw(medium)) ///
(scatter coef t if test=="Choice v Baseline", lcolor(cranberry) m(O) mcolor(cranberry) lp(dot)) ///
(scatter coef t if test=="Ownerhip v Baseline", lcolor(midblue) m(T) mcolor(midblue) lp(dot)), ///
xlabel(1 2 3 4 5 6) yline(0, lp(dash) lcolor(black) extend) xline(3.5) ///
legend(rows(1) region(lwidth(none)) order (3 4) ///
label(3 "Choice v Baseline") label(4 "Ownerhip v Baseline")) ///
xtitle("") ytitle("Zoom", size(large)) ///
title("") name(Zoom, replace)
restore

preserve
keep if stock==2
twoway ///
(rcap ch cl t if test=="Choice v Baseline", lcolor(cranberry) lw(medium)) ///
(rcap ch cl t if test=="Ownerhip v Baseline", lcolor(midblue) lw(medium)) ///
(scatter coef t if test=="Choice v Baseline", lcolor(cranberry) m(O) mcolor(cranberry) lp(dot)) ///
(scatter coef t if test=="Ownerhip v Baseline", lcolor(midblue) m(T) mcolor(midblue) lp(dot)), ///
xlabel(1 2 3 4 5 6) yline(0, lp(dash) lcolor(black) extend) xline(3.5) ///
legend(rows(1) region(lwidth(none)) order (3 4) ///
label(3 "Choice v Baseline") label(4 "Ownerhip v Baseline")) ///
xtitle("") ytitle("Facebook", size(large)) ///
title("") name(Facebook, replace)
restore

preserve
keep if stock==3
twoway ///
(rcap ch cl t if test=="Choice v Baseline", lcolor(cranberry) lw(medium)) ///
(rcap ch cl t if test=="Ownerhip v Baseline", lcolor(midblue) lw(medium)) ///
(scatter coef t if test=="Choice v Baseline", lcolor(cranberry) m(O) mcolor(cranberry) lp(dot)) ///
(scatter coef t if test=="Ownerhip v Baseline", lcolor(midblue) m(T) mcolor(midblue) lp(dot)), ///
xlabel(1 2 3 4 5 6) yline(0, lp(dash) lcolor(black) extend) xline(3.5) ///
legend(rows(1) region(lwidth(none)) order (3 4) ///
label(3 "Choice v Baseline") label(4 "Ownerhip v Baseline")) ///
xtitle("") ytitle("Netflix", size(large)) ///
title("") name(Netflix, replace)
restore

preserve
keep if stock==4
twoway ///
(rcap ch cl t if test=="Choice v Baseline", lcolor(cranberry) lw(medium)) ///
(rcap ch cl t if test=="Ownerhip v Baseline", lcolor(midblue) lw(medium)) ///
(scatter coef t if test=="Choice v Baseline", lcolor(cranberry) m(O) mcolor(cranberry) lp(dot)) ///
(scatter coef t if test=="Ownerhip v Baseline", lcolor(midblue) m(T) mcolor(midblue) lp(dot)), ///
xlabel(1 2 3 4 5 6) yline(0, lp(dash) lcolor(black) extend) xline(3.5) ///
legend(rows(1) region(lwidth(none)) order (3 4) ///
label(3 "Choice v Baseline") label(4 "Ownerhip v Baseline")) ///
xtitle("week") ytitle("Tesla", size(large)) ///
title("") name(Tesla, replace)
restore

preserve
keep if stock==5
twoway ///
(rcap ch cl t if test=="Choice v Baseline", lcolor(cranberry) lw(medium)) ///
(rcap ch cl t if test=="Ownerhip v Baseline", lcolor(midblue) lw(medium)) ///
(scatter coef t if test=="Choice v Baseline", lcolor(cranberry) m(O) mcolor(cranberry) lp(dot)) ///
(scatter coef t if test=="Ownerhip v Baseline", lcolor(midblue) m(T) mcolor(midblue) lp(dot)), ///
xlabel(1 2 3 4 5 6) yline(0, lp(dash) lcolor(black) extend) xline(3.5) ///
legend(rows(1) region(lwidth(none)) order (3 4) ///
label(3 "Choice v Baseline") label(4 "Ownerhip v Baseline")) ///
xtitle("week") ytitle("Uber", size(large)) ///
title("") name(Uber, replace)
restore

grc1leg  Uber Tesla Facebook Netflix Zoom Alibaba, graphregion(margin(zero)) imargin(tiny) rows(3) ycom legendfrom(Alibaba) span iscale(.6) name(Fig_weeks, replace)


*****************************************************************************************************************************
**************************                         Table E4 in the Internet Appendix:             ***************************
**************         Treatment effects on predicted returns for each stock and week in Study 2              ***************
*****************************************************************************************************************************
*First have to upload again the original data
use Study_2_Data.dta, clear

preserve
*week-stock interaction effects:
*set week=0 for the day of the prediction:
replace week=0 if post==0 & week==4
*NEW:
replace week=0 if week==3 & day==18
*drop week 7 (very few observations from late subjects)
drop if week==7
gen return = (price - purchase_price)/purchase_price
table week stock if treatment>0, c(mean return)
replace pred_norm = 100*pred_norm
reghdfe pred_norm i.week##i.stock##i.treatment##i.owned, absorb(stock#day idstock) cluster(id) coeflegend
*Now compute stock by stock diff-in-diff: 
*week1-week0, week2-week0, week3-week0 week4-week0, week5-week0, week6-week0

*****************************************************************************************************************************
****************************     Choice(owned) vs Baseline     **************************************************************
*****************************************************************************************************************************

*Tesla
*Week1:
lincom (_b[1.week#1.treatment] + _b[1.week#1.owned] + _b[1.week#4.stock#1.treatment] + _b[1.week#4.stock#1.owned] ///
+ _b[1.week#1.treatment#1.owned] + _b[1.week#4.stock#1.treatment#1.owned])
*Week2:
lincom (_b[2.week#1.treatment] + _b[2.week#1.owned] + _b[2.week#4.stock#1.treatment] + _b[2.week#4.stock#1.owned] ///
+ _b[2.week#1.treatment#1.owned] + _b[2.week#4.stock#1.treatment#1.owned])
*Week3:
lincom (_b[3.week#1.treatment] + _b[3.week#1.owned] + _b[3.week#4.stock#1.treatment] + _b[3.week#4.stock#1.owned] ///
+ _b[3.week#1.treatment#1.owned] + _b[3.week#4.stock#1.treatment#1.owned])
*Week4:
lincom (_b[4.week#1.treatment] + _b[4.week#1.owned] + _b[4.week#4.stock#1.treatment] + _b[4.week#4.stock#1.owned] ///
+ _b[4.week#1.treatment#1.owned] + _b[4.week#4.stock#1.treatment#1.owned])
*Week5:
lincom (_b[5.week#1.treatment] + _b[5.week#1.owned] + _b[5.week#4.stock#1.treatment] + _b[5.week#4.stock#1.owned] ///
+ _b[5.week#1.treatment#1.owned] + _b[5.week#4.stock#1.treatment#1.owned])
*Week6:
lincom (_b[6.week#1.treatment] + _b[6.week#1.owned] + _b[6.week#4.stock#1.treatment] + _b[6.week#4.stock#1.owned] ///
+ _b[6.week#1.treatment#1.owned] + _b[6.week#4.stock#1.treatment#1.owned])

*Uber
*Week1:
lincom (_b[1.week#1.treatment] + _b[1.week#1.owned] + _b[1.week#5.stock#1.treatment] + _b[1.week#5.stock#1.owned] ///
+ _b[1.week#1.treatment#1.owned] + _b[1.week#5.stock#1.treatment#1.owned])
*Week2:
lincom (_b[2.week#1.treatment] + _b[2.week#1.owned] + _b[2.week#5.stock#1.treatment] + _b[2.week#5.stock#1.owned] ///
+ _b[2.week#1.treatment#1.owned] + _b[2.week#5.stock#1.treatment#1.owned])
*Week3:
lincom (_b[3.week#1.treatment] + _b[3.week#1.owned] + _b[3.week#5.stock#1.treatment] + _b[3.week#5.stock#1.owned] ///
+ _b[3.week#1.treatment#1.owned] + _b[3.week#5.stock#1.treatment#1.owned])
*Week4:
lincom (_b[4.week#1.treatment] + _b[4.week#1.owned] + _b[4.week#5.stock#1.treatment] + _b[4.week#5.stock#1.owned] ///
+ _b[4.week#1.treatment#1.owned] + _b[4.week#5.stock#1.treatment#1.owned])
*Week5:
lincom (_b[5.week#1.treatment] + _b[5.week#1.owned] + _b[5.week#5.stock#1.treatment] + _b[5.week#5.stock#1.owned] ///
+ _b[5.week#1.treatment#1.owned] + _b[5.week#5.stock#1.treatment#1.owned])
*Week6:
lincom (_b[6.week#1.treatment] + _b[6.week#1.owned] + _b[6.week#5.stock#1.treatment] + _b[6.week#5.stock#1.owned] ///
+ _b[6.week#1.treatment#1.owned] + _b[6.week#5.stock#1.treatment#1.owned])

*Facebook
*Week1:
lincom (_b[1.week#1.treatment] + _b[1.week#1.owned] + _b[1.week#2.stock#1.treatment] + _b[1.week#2.stock#1.owned] ///
+ _b[1.week#1.treatment#1.owned] + _b[1.week#2.stock#1.treatment#1.owned])
*Week2:
lincom (_b[2.week#1.treatment] + _b[2.week#1.owned] + _b[2.week#2.stock#1.treatment] + _b[2.week#2.stock#1.owned] ///
+ _b[2.week#1.treatment#1.owned] + _b[2.week#2.stock#1.treatment#1.owned])
*Week3:
lincom (_b[3.week#1.treatment] + _b[3.week#1.owned] + _b[3.week#2.stock#1.treatment] + _b[3.week#2.stock#1.owned] ///
+ _b[3.week#1.treatment#1.owned] + _b[3.week#2.stock#1.treatment#1.owned])
*Week4:
lincom (_b[4.week#1.treatment] + _b[4.week#1.owned] + _b[4.week#2.stock#1.treatment] + _b[4.week#2.stock#1.owned] ///
+ _b[4.week#1.treatment#1.owned] + _b[4.week#2.stock#1.treatment#1.owned])
*Week5:
lincom (_b[5.week#1.treatment] + _b[5.week#1.owned] + _b[5.week#2.stock#1.treatment] + _b[5.week#2.stock#1.owned] ///
+ _b[5.week#1.treatment#1.owned] + _b[5.week#2.stock#1.treatment#1.owned])
*Week6:
lincom (_b[6.week#1.treatment] + _b[6.week#1.owned] + _b[6.week#2.stock#1.treatment] + _b[6.week#2.stock#1.owned] ///
+ _b[6.week#1.treatment#1.owned] + _b[6.week#2.stock#1.treatment#1.owned])

*Netflix
*Week1:
lincom (_b[1.week#1.treatment] + _b[1.week#1.owned] + _b[1.week#3.stock#1.treatment] + _b[1.week#3.stock#1.owned] ///
+ _b[1.week#1.treatment#1.owned] + _b[1.week#3.stock#1.treatment#1.owned])
*Week2:
lincom (_b[2.week#1.treatment] + _b[2.week#1.owned] + _b[2.week#3.stock#1.treatment] + _b[2.week#3.stock#1.owned] ///
+ _b[2.week#1.treatment#1.owned] + _b[2.week#3.stock#1.treatment#1.owned])
*Week3:
lincom (_b[3.week#1.treatment] + _b[3.week#1.owned] + _b[3.week#3.stock#1.treatment] + _b[3.week#3.stock#1.owned] ///
+ _b[3.week#1.treatment#1.owned] + _b[3.week#3.stock#1.treatment#1.owned])
*Week4:
lincom (_b[4.week#1.treatment] + _b[4.week#1.owned] + _b[4.week#3.stock#1.treatment] + _b[4.week#3.stock#1.owned] ///
+ _b[4.week#1.treatment#1.owned] + _b[4.week#3.stock#1.treatment#1.owned])
*Week5:
lincom (_b[5.week#1.treatment] + _b[5.week#1.owned] + _b[5.week#3.stock#1.treatment] + _b[5.week#3.stock#1.owned] ///
+ _b[5.week#1.treatment#1.owned] + _b[5.week#3.stock#1.treatment#1.owned])
*Week6:
lincom (_b[6.week#1.treatment] + _b[6.week#1.owned] + _b[6.week#3.stock#1.treatment] + _b[6.week#3.stock#1.owned] ///
+ _b[6.week#1.treatment#1.owned] + _b[6.week#3.stock#1.treatment#1.owned])

*Alibaba
*Week1:
lincom ( _b[1.week#1.treatment] + _b[1.week#1.owned] + _b[1.week#1.treatment#1.owned])
*Week2:
lincom ( _b[2.week#1.treatment] + _b[2.week#1.owned] + _b[2.week#1.treatment#1.owned])
*Week3:
lincom ( _b[3.week#1.treatment] + _b[3.week#1.owned] + _b[3.week#1.treatment#1.owned])
*Week4 (p=0.0696), size=1.35:
lincom ( _b[4.week#1.treatment] + _b[4.week#1.owned] + _b[4.week#1.treatment#1.owned])
*Week5 (p=0.0036) size=2.55:
lincom ( _b[5.week#1.treatment] + _b[5.week#1.owned] + _b[5.week#1.treatment#1.owned])
*Week6 (p=0.0099), size=2.85:
lincom ( _b[6.week#1.treatment] + _b[6.week#1.owned] + _b[6.week#1.treatment#1.owned])

*Zoom
*Week1:
lincom (_b[1.week#1.treatment] + _b[1.week#1.owned] + _b[1.week#6.stock#1.treatment] + _b[1.week#6.stock#1.owned] ///
+ _b[1.week#1.treatment#1.owned] + _b[1.week#6.stock#1.treatment#1.owned])
*Week2:
lincom (_b[2.week#1.treatment] + _b[2.week#1.owned] + _b[2.week#6.stock#1.treatment] + _b[2.week#6.stock#1.owned] ///
+ _b[2.week#1.treatment#1.owned] + _b[2.week#6.stock#1.treatment#1.owned])
*Week3:
lincom (_b[3.week#1.treatment] + _b[3.week#1.owned] + _b[3.week#6.stock#1.treatment] + _b[3.week#6.stock#1.owned] ///
+ _b[3.week#1.treatment#1.owned] + _b[3.week#6.stock#1.treatment#1.owned])
*Week4:
lincom (_b[4.week#1.treatment] + _b[4.week#1.owned] + _b[4.week#6.stock#1.treatment] + _b[4.week#6.stock#1.owned] ///
+ _b[4.week#1.treatment#1.owned] + _b[4.week#6.stock#1.treatment#1.owned])
*Week5:
lincom (_b[5.week#1.treatment] + _b[5.week#1.owned] + _b[5.week#6.stock#1.treatment] + _b[5.week#6.stock#1.owned] ///
+ _b[5.week#1.treatment#1.owned] + _b[5.week#6.stock#1.treatment#1.owned])
*Week6:
lincom (_b[6.week#1.treatment] + _b[6.week#1.owned] + _b[6.week#6.stock#1.treatment] + _b[6.week#6.stock#1.owned] ///
+ _b[6.week#1.treatment#1.owned] + _b[6.week#6.stock#1.treatment#1.owned])

*****************************************************************************************************************************
****************************     Ownership(owned) vs Baseline      **************************************************************
*****************************************************************************************************************************

*Tesla
*Week1: p=0.0920, size=1.589
lincom (_b[1.week#2.treatment] + _b[1.week#1.owned] + _b[1.week#4.stock#2.treatment] + _b[1.week#4.stock#1.owned] + _b[1.week#2.treatment#1.owned] + _b[1.week#4.stock#2.treatment#1.owned])
*Week2:
lincom (_b[2.week#2.treatment] + _b[2.week#1.owned] + _b[2.week#4.stock#2.treatment] + _b[2.week#4.stock#1.owned] + _b[2.week#2.treatment#1.owned] + _b[2.week#4.stock#2.treatment#1.owned])
*Week3:
lincom (_b[3.week#2.treatment] + _b[3.week#1.owned] + _b[3.week#4.stock#2.treatment] + _b[3.week#4.stock#1.owned] + _b[3.week#2.treatment#1.owned] + _b[3.week#4.stock#2.treatment#1.owned])
*Week4:
lincom (_b[4.week#2.treatment] + _b[4.week#1.owned] + _b[4.week#4.stock#2.treatment] + _b[4.week#4.stock#1.owned] + _b[4.week#2.treatment#1.owned] + _b[4.week#4.stock#2.treatment#1.owned])
*Week5:
lincom (_b[5.week#2.treatment] + _b[5.week#1.owned] + _b[5.week#4.stock#2.treatment] + _b[5.week#4.stock#1.owned] + _b[5.week#2.treatment#1.owned] + _b[5.week#4.stock#2.treatment#1.owned])
*Week6:
lincom (_b[6.week#2.treatment] + _b[6.week#1.owned] + _b[6.week#4.stock#2.treatment] + _b[6.week#4.stock#1.owned] + _b[6.week#2.treatment#1.owned] + _b[6.week#4.stock#2.treatment#1.owned])

*Uber
*Week1:
lincom (_b[1.week#2.treatment] + _b[1.week#1.owned] + _b[1.week#5.stock#2.treatment] + _b[1.week#5.stock#1.owned] + _b[1.week#2.treatment#1.owned] + _b[1.week#5.stock#2.treatment#1.owned])
*Week2:
lincom (_b[2.week#2.treatment] + _b[2.week#1.owned] + _b[2.week#5.stock#2.treatment] + _b[2.week#5.stock#1.owned] + _b[2.week#2.treatment#1.owned] + _b[2.week#5.stock#2.treatment#1.owned])
*Week3:
lincom (_b[3.week#2.treatment] + _b[3.week#1.owned] + _b[3.week#5.stock#2.treatment] + _b[3.week#5.stock#1.owned] + _b[3.week#2.treatment#1.owned] + _b[3.week#5.stock#2.treatment#1.owned])
*Week4:
lincom (_b[4.week#2.treatment] + _b[4.week#1.owned] + _b[4.week#5.stock#2.treatment] + _b[4.week#5.stock#1.owned] + _b[4.week#2.treatment#1.owned] + _b[4.week#5.stock#2.treatment#1.owned])
*Week5:
lincom (_b[5.week#2.treatment] + _b[5.week#1.owned] + _b[5.week#5.stock#2.treatment] + _b[5.week#5.stock#1.owned] + _b[5.week#2.treatment#1.owned] + _b[5.week#5.stock#2.treatment#1.owned])
*Week6:
lincom (_b[6.week#2.treatment] + _b[6.week#1.owned] + _b[6.week#5.stock#2.treatment] + _b[6.week#5.stock#1.owned] + _b[6.week#2.treatment#1.owned] + _b[6.week#5.stock#2.treatment#1.owned])

*Facebook
*Week1:
lincom (_b[1.week#2.treatment] + _b[1.week#1.owned] + _b[1.week#2.stock#2.treatment] + _b[1.week#2.stock#1.owned] + _b[1.week#2.treatment#1.owned] + _b[1.week#2.stock#2.treatment#1.owned])
*Week2:
lincom (_b[2.week#2.treatment] + _b[2.week#1.owned] + _b[2.week#2.stock#2.treatment] + _b[2.week#2.stock#1.owned] + _b[2.week#2.treatment#1.owned] + _b[2.week#2.stock#2.treatment#1.owned])
*Week3:
lincom (_b[3.week#2.treatment] + _b[3.week#1.owned] + _b[3.week#2.stock#2.treatment] + _b[3.week#2.stock#1.owned] + _b[3.week#2.treatment#1.owned] + _b[3.week#2.stock#2.treatment#1.owned])
*Week4:
lincom (_b[4.week#2.treatment] + _b[4.week#1.owned] + _b[4.week#2.stock#2.treatment] + _b[4.week#2.stock#1.owned] + _b[4.week#2.treatment#1.owned] + _b[4.week#2.stock#2.treatment#1.owned])
*Week5:
lincom (_b[5.week#2.treatment] + _b[5.week#1.owned] + _b[5.week#2.stock#2.treatment] + _b[5.week#2.stock#1.owned] + _b[5.week#2.treatment#1.owned] + _b[5.week#2.stock#2.treatment#1.owned])
*Week6:
lincom (_b[6.week#2.treatment] + _b[6.week#1.owned] + _b[6.week#2.stock#2.treatment] + _b[6.week#2.stock#1.owned] + _b[6.week#2.treatment#1.owned] + _b[6.week#2.stock#2.treatment#1.owned])

*Netflix
*Week1:
lincom (_b[1.week#2.treatment] + _b[1.week#1.owned] + _b[1.week#3.stock#2.treatment] + _b[1.week#3.stock#1.owned] + _b[1.week#2.treatment#1.owned] + _b[1.week#3.stock#2.treatment#1.owned])
*Week2:
lincom (_b[2.week#2.treatment] + _b[2.week#1.owned] + _b[2.week#3.stock#2.treatment] + _b[2.week#3.stock#1.owned] + _b[2.week#2.treatment#1.owned] + _b[2.week#3.stock#2.treatment#1.owned])
*Week3:
lincom (_b[3.week#2.treatment] + _b[3.week#1.owned] + _b[3.week#3.stock#2.treatment] + _b[3.week#3.stock#1.owned] + _b[3.week#2.treatment#1.owned] + _b[3.week#3.stock#2.treatment#1.owned])
*Week4:
lincom (_b[4.week#2.treatment] + _b[4.week#1.owned] + _b[4.week#3.stock#2.treatment] + _b[4.week#3.stock#1.owned] + _b[4.week#2.treatment#1.owned] + _b[4.week#3.stock#2.treatment#1.owned])
*Week5:
lincom (_b[5.week#2.treatment] + _b[5.week#1.owned] + _b[5.week#3.stock#2.treatment] + _b[5.week#3.stock#1.owned] + _b[5.week#2.treatment#1.owned] + _b[5.week#3.stock#2.treatment#1.owned])
*Week6:
lincom (_b[6.week#2.treatment] + _b[6.week#1.owned] + _b[6.week#3.stock#2.treatment] + _b[6.week#3.stock#1.owned] + _b[6.week#2.treatment#1.owned] + _b[6.week#3.stock#2.treatment#1.owned])

*Alibaba
*Week1:
lincom ( _b[1.week#2.treatment] + _b[1.week#1.owned] )
*Week2:
lincom ( _b[2.week#2.treatment] + _b[2.week#1.owned] )
*Week3:
lincom ( _b[3.week#2.treatment] + _b[3.week#1.owned] )
*Week4 (p=0.0457) size = 1.35:
lincom ( _b[4.week#2.treatment] + _b[4.week#1.owned] )
*Week5 (p=0.0067) size = 2.43:
lincom ( _b[5.week#2.treatment] + _b[5.week#1.owned] )
*Week6 (p=0.0070) size = 2.83:
lincom ( _b[6.week#2.treatment] + _b[6.week#1.owned] )

*Zoom
*Week1:
lincom (_b[1.week#2.treatment] + _b[1.week#1.owned] + _b[1.week#6.stock#2.treatment] + _b[1.week#6.stock#1.owned] + _b[1.week#2.treatment#1.owned] + _b[1.week#6.stock#2.treatment#1.owned])
*Week2:
lincom (_b[2.week#2.treatment] + _b[2.week#1.owned] + _b[2.week#6.stock#2.treatment] + _b[2.week#6.stock#1.owned] + _b[2.week#2.treatment#1.owned] + _b[2.week#6.stock#2.treatment#1.owned])
*Week3: p=0.0975, size=1.168
lincom (_b[3.week#2.treatment] + _b[3.week#1.owned] + _b[3.week#6.stock#2.treatment] + _b[3.week#6.stock#1.owned] + _b[3.week#2.treatment#1.owned] + _b[3.week#6.stock#2.treatment#1.owned])
*Week4: p=0.302, size=0.762
lincom (_b[4.week#2.treatment] + _b[4.week#1.owned] + _b[4.week#6.stock#2.treatment] + _b[4.week#6.stock#1.owned] + _b[4.week#2.treatment#1.owned] + _b[4.week#6.stock#2.treatment#1.owned])
*Week5: p=0.0098, size=2.456
lincom (_b[5.week#2.treatment] + _b[5.week#1.owned] + _b[5.week#6.stock#2.treatment] + _b[5.week#6.stock#1.owned] + _b[5.week#2.treatment#1.owned] + _b[5.week#6.stock#2.treatment#1.owned])
*Week6: p=0.0449, size=2.6
lincom (_b[6.week#2.treatment] + _b[6.week#1.owned] + _b[6.week#6.stock#2.treatment] + _b[6.week#6.stock#1.owned] + _b[6.week#2.treatment#1.owned] + _b[6.week#6.stock#2.treatment#1.owned])


*****************************************************************************************************************************
****************************     Choice(owned) vs Ownership     **************************************************************
***************************************************************************************************************************** 

*Tesla
*Week1:
lincom (_b[1.week#1.treatment] + _b[1.week#4.stock#1.treatment] + _b[1.week#1.treatment#1.owned] + _b[1.week#4.stock#1.treatment#1.owned] ///
- _b[1.week#2.treatment] - _b[1.week#4.stock#2.treatment] - _b[1.week#2.treatment#1.owned] -  _b[1.week#4.stock#2.treatment#1.owned] )
*Week2:
lincom (_b[2.week#1.treatment] + _b[2.week#4.stock#1.treatment] + _b[2.week#1.treatment#1.owned] + _b[2.week#4.stock#1.treatment#1.owned] ///
- _b[2.week#2.treatment] - _b[2.week#4.stock#2.treatment] - _b[2.week#2.treatment#1.owned] -  _b[2.week#4.stock#2.treatment#1.owned] )
*Week3:
lincom (_b[3.week#1.treatment] + _b[3.week#4.stock#1.treatment] + _b[3.week#1.treatment#1.owned] + _b[3.week#4.stock#1.treatment#1.owned] ///
- _b[3.week#2.treatment] - _b[3.week#4.stock#2.treatment] - _b[3.week#2.treatment#1.owned] -  _b[3.week#4.stock#2.treatment#1.owned] )
*Week4:
lincom (_b[4.week#1.treatment] + _b[4.week#4.stock#1.treatment] + _b[4.week#1.treatment#1.owned] + _b[4.week#4.stock#1.treatment#1.owned] ///
- _b[4.week#2.treatment] - _b[4.week#4.stock#2.treatment] - _b[4.week#2.treatment#1.owned] -  _b[4.week#4.stock#2.treatment#1.owned] )
*Week5:
lincom (_b[5.week#1.treatment] + _b[5.week#4.stock#1.treatment] + _b[5.week#1.treatment#1.owned] + _b[5.week#4.stock#1.treatment#1.owned] ///
- _b[5.week#2.treatment] - _b[5.week#4.stock#2.treatment] - _b[5.week#2.treatment#1.owned] -  _b[5.week#4.stock#2.treatment#1.owned] )
*Week6:
lincom (_b[6.week#1.treatment] + _b[6.week#4.stock#1.treatment] + _b[6.week#1.treatment#1.owned] + _b[6.week#4.stock#1.treatment#1.owned] ///
- _b[6.week#2.treatment] - _b[6.week#4.stock#2.treatment] - _b[6.week#2.treatment#1.owned] -  _b[6.week#4.stock#2.treatment#1.owned] )

*Uber
*Week1:
lincom (_b[1.week#1.treatment] + _b[1.week#5.stock#1.treatment] + _b[1.week#1.treatment#1.owned] + _b[1.week#5.stock#1.treatment#1.owned] ///
- _b[1.week#2.treatment] - _b[1.week#5.stock#2.treatment] - _b[1.week#2.treatment#1.owned] -  _b[1.week#5.stock#2.treatment#1.owned] )
*Week2:
lincom (_b[2.week#1.treatment] + _b[2.week#5.stock#1.treatment] + _b[2.week#1.treatment#1.owned] + _b[2.week#5.stock#1.treatment#1.owned] ///
- _b[2.week#2.treatment] - _b[2.week#5.stock#2.treatment] - _b[2.week#2.treatment#1.owned] -  _b[2.week#5.stock#2.treatment#1.owned] )
*Week3:
lincom (_b[3.week#1.treatment] + _b[3.week#5.stock#1.treatment] + _b[3.week#1.treatment#1.owned] + _b[3.week#5.stock#1.treatment#1.owned] ///
- _b[3.week#2.treatment] - _b[3.week#5.stock#2.treatment] - _b[3.week#2.treatment#1.owned] -  _b[3.week#5.stock#2.treatment#1.owned] )
*Week4:
lincom (_b[4.week#1.treatment] + _b[4.week#5.stock#1.treatment] + _b[4.week#1.treatment#1.owned] + _b[4.week#5.stock#1.treatment#1.owned] ///
- _b[4.week#2.treatment] - _b[4.week#5.stock#2.treatment] - _b[4.week#2.treatment#1.owned] -  _b[4.week#5.stock#2.treatment#1.owned] )
*Week5:
lincom (_b[5.week#1.treatment] + _b[5.week#5.stock#1.treatment] + _b[5.week#1.treatment#1.owned] + _b[5.week#5.stock#1.treatment#1.owned] ///
- _b[5.week#2.treatment] - _b[5.week#5.stock#2.treatment] - _b[5.week#2.treatment#1.owned] -  _b[5.week#5.stock#2.treatment#1.owned] )
*Week6:
lincom (_b[6.week#1.treatment] + _b[6.week#5.stock#1.treatment] + _b[6.week#1.treatment#1.owned] + _b[6.week#5.stock#1.treatment#1.owned] ///
- _b[6.week#2.treatment] - _b[6.week#5.stock#2.treatment] - _b[6.week#2.treatment#1.owned] -  _b[6.week#5.stock#2.treatment#1.owned] )

*Facebook
*Week1:
lincom (_b[1.week#1.treatment] + _b[1.week#2.stock#1.treatment] + _b[1.week#1.treatment#1.owned] + _b[1.week#2.stock#1.treatment#1.owned] ///
- _b[1.week#2.treatment] - _b[1.week#2.stock#2.treatment] - _b[1.week#2.treatment#1.owned] -  _b[1.week#2.stock#2.treatment#1.owned] )
*Week2:
lincom (_b[2.week#1.treatment] + _b[2.week#2.stock#1.treatment] + _b[2.week#1.treatment#1.owned] + _b[2.week#2.stock#1.treatment#1.owned] ///
- _b[2.week#2.treatment] - _b[2.week#2.stock#2.treatment] - _b[2.week#2.treatment#1.owned] -  _b[2.week#2.stock#2.treatment#1.owned] )
*Week3:
lincom (_b[3.week#1.treatment] + _b[3.week#2.stock#1.treatment] + _b[3.week#1.treatment#1.owned] + _b[3.week#2.stock#1.treatment#1.owned] ///
- _b[3.week#2.treatment] - _b[3.week#2.stock#2.treatment] - _b[3.week#2.treatment#1.owned] -  _b[3.week#2.stock#2.treatment#1.owned] )
*Week4:
lincom (_b[4.week#1.treatment] + _b[4.week#2.stock#1.treatment] + _b[4.week#1.treatment#1.owned] + _b[4.week#2.stock#1.treatment#1.owned] ///
- _b[4.week#2.treatment] - _b[4.week#2.stock#2.treatment] - _b[4.week#2.treatment#1.owned] -  _b[4.week#2.stock#2.treatment#1.owned] )
*Week5:
lincom (_b[5.week#1.treatment] + _b[5.week#2.stock#1.treatment] + _b[5.week#1.treatment#1.owned] + _b[5.week#2.stock#1.treatment#1.owned] ///
- _b[5.week#2.treatment] - _b[5.week#2.stock#2.treatment] - _b[5.week#2.treatment#1.owned] -  _b[5.week#2.stock#2.treatment#1.owned] )
*Week6:
lincom (_b[6.week#1.treatment] + _b[6.week#2.stock#1.treatment] + _b[6.week#1.treatment#1.owned] + _b[6.week#2.stock#1.treatment#1.owned] ///
- _b[6.week#2.treatment] - _b[6.week#2.stock#2.treatment] - _b[6.week#2.treatment#1.owned] -  _b[6.week#2.stock#2.treatment#1.owned] )

*Netflix
*Week1:
lincom (_b[1.week#1.treatment] + _b[1.week#3.stock#1.treatment] + _b[1.week#1.treatment#1.owned] + _b[1.week#3.stock#1.treatment#1.owned] ///
- _b[1.week#2.treatment] - _b[1.week#3.stock#2.treatment] - _b[1.week#2.treatment#1.owned] -  _b[1.week#3.stock#2.treatment#1.owned] )
*Week2:
lincom (_b[2.week#1.treatment] + _b[2.week#3.stock#1.treatment] + _b[2.week#1.treatment#1.owned] + _b[2.week#3.stock#1.treatment#1.owned] ///
- _b[2.week#2.treatment] - _b[2.week#3.stock#2.treatment] - _b[2.week#2.treatment#1.owned] -  _b[2.week#3.stock#2.treatment#1.owned] )
*Week3:
lincom (_b[3.week#1.treatment] + _b[3.week#3.stock#1.treatment] + _b[3.week#1.treatment#1.owned] + _b[3.week#3.stock#1.treatment#1.owned] ///
- _b[3.week#2.treatment] - _b[3.week#3.stock#2.treatment] - _b[3.week#2.treatment#1.owned] -  _b[3.week#3.stock#2.treatment#1.owned] )
*Week4:
lincom (_b[4.week#1.treatment] + _b[4.week#3.stock#1.treatment] + _b[4.week#1.treatment#1.owned] + _b[4.week#3.stock#1.treatment#1.owned] ///
- _b[4.week#2.treatment] - _b[4.week#3.stock#2.treatment] - _b[4.week#2.treatment#1.owned] -  _b[4.week#3.stock#2.treatment#1.owned] )
*Week5:
lincom (_b[5.week#1.treatment] + _b[5.week#3.stock#1.treatment] + _b[5.week#1.treatment#1.owned] + _b[5.week#3.stock#1.treatment#1.owned] ///
- _b[5.week#2.treatment] - _b[5.week#3.stock#2.treatment] - _b[5.week#2.treatment#1.owned] -  _b[5.week#3.stock#2.treatment#1.owned] )
*Week6:
lincom (_b[6.week#1.treatment] + _b[6.week#3.stock#1.treatment] + _b[6.week#1.treatment#1.owned] + _b[6.week#3.stock#1.treatment#1.owned] ///
- _b[6.week#2.treatment] - _b[6.week#3.stock#2.treatment] - _b[6.week#2.treatment#1.owned] -  _b[6.week#3.stock#2.treatment#1.owned] )

*Alibaba
*Week1:
lincom (_b[1.week#1.treatment] + _b[1.week#1.treatment#1.owned] - _b[1.week#2.treatment])
*Week2:
lincom (_b[2.week#1.treatment] + _b[2.week#1.treatment#1.owned] - _b[2.week#2.treatment])
*Week3:
lincom (_b[3.week#1.treatment] + _b[3.week#1.treatment#1.owned] - _b[3.week#2.treatment])
*Week4 (p=0.0696), size=1.35:
lincom (_b[4.week#1.treatment] + _b[4.week#1.treatment#1.owned] - _b[4.week#2.treatment])
*Week5 (p=0.0036) size=2.55:
lincom (_b[5.week#1.treatment] + _b[5.week#1.treatment#1.owned] - _b[5.week#2.treatment])
*Week6 (p=0.0099), size=2.85:
lincom (_b[6.week#1.treatment] + _b[6.week#1.treatment#1.owned] - _b[6.week#2.treatment])

*Zoom
*Week1:
lincom (_b[1.week#1.treatment] + _b[1.week#6.stock#1.treatment] + _b[1.week#1.treatment#1.owned] + _b[1.week#6.stock#1.treatment#1.owned] ///
- _b[1.week#2.treatment] - _b[1.week#6.stock#2.treatment] - _b[1.week#2.treatment#1.owned] -  _b[1.week#6.stock#2.treatment#1.owned] )
*Week2:
lincom (_b[2.week#1.treatment] + _b[2.week#6.stock#1.treatment] + _b[2.week#1.treatment#1.owned] + _b[2.week#6.stock#1.treatment#1.owned] ///
- _b[2.week#2.treatment] - _b[2.week#6.stock#2.treatment] - _b[2.week#2.treatment#1.owned] -  _b[2.week#6.stock#2.treatment#1.owned] )
*Week3:
lincom (_b[3.week#1.treatment] + _b[3.week#6.stock#1.treatment] + _b[3.week#1.treatment#1.owned] + _b[3.week#6.stock#1.treatment#1.owned] ///
- _b[3.week#2.treatment] - _b[3.week#6.stock#2.treatment] - _b[3.week#2.treatment#1.owned] -  _b[3.week#6.stock#2.treatment#1.owned] )
*Week4:
lincom (_b[4.week#1.treatment] + _b[4.week#6.stock#1.treatment] + _b[4.week#1.treatment#1.owned] + _b[4.week#6.stock#1.treatment#1.owned] ///
- _b[4.week#2.treatment] - _b[4.week#6.stock#2.treatment] - _b[4.week#2.treatment#1.owned] -  _b[4.week#6.stock#2.treatment#1.owned] )
*Week5:
lincom (_b[5.week#1.treatment] + _b[5.week#6.stock#1.treatment] + _b[5.week#1.treatment#1.owned] + _b[5.week#6.stock#1.treatment#1.owned] ///
- _b[5.week#2.treatment] - _b[5.week#6.stock#2.treatment] - _b[5.week#2.treatment#1.owned] -  _b[5.week#6.stock#2.treatment#1.owned] )
*Week6:
lincom (_b[6.week#1.treatment] + _b[6.week#6.stock#1.treatment] + _b[6.week#1.treatment#1.owned] + _b[6.week#6.stock#1.treatment#1.owned] ///
- _b[6.week#2.treatment] - _b[6.week#6.stock#2.treatment] - _b[6.week#2.treatment#1.owned] -  _b[6.week#6.stock#2.treatment#1.owned] )

restore


*****************************************************************************************************************************
******************    TABLE 5 in the main text: Treatment effects on predicted probabilities in Study 2     *****************
*****************************************************************************************************************************

*ALL STOCKS TOGETHER
reghdfe predprob i.owned##i.post##i.treatment, absorb(stock#day idstock) cluster(id)
outreg2 using Reg_online2, adjr2 excel ctitle(All) stats(coef se) dec(3) replace
*Diff-in-diff Choice vs Baseline:
lincom (_b[1.post#1.owned] + _b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment])
*Diff-in-diff Ownership vs Baseline:
lincom (_b[1.post#2.treatment] + _b[1.post#1.owned])
*Diff-in-diff Choice vs Ownership:
lincom (_b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment] - (_b[1.post#2.treatment]))

*ONLY WINNERS (UBER, TESLA)
preserve
keep if stockgroup==3
reghdfe predprob i.owned##i.post##i.treatment, absorb(stock#day idstock) cluster(id)
outreg2 using Reg_online2, adjr2 excel ctitle(Winners) stats(coef se) dec(3) append
*Diff-in-diff Choice vs Baseline:
lincom (_b[1.post#1.owned] + _b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment])
*Diff-in-diff Ownership vs Baseline:
lincom (_b[1.post#2.treatment] + _b[1.post#1.owned])
*Diff-in-diff Choice vs Ownership:
lincom (_b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment] - (_b[1.post#2.treatment]))
restore

*ONLY NEUTRAL (FACEBOOK, NETFLIX)
preserve
keep if stockgroup==2
reghdfe predprob i.owned##i.post##i.treatment, absorb(stock#day idstock) cluster(id)
outreg2 using Reg_online2, adjr2 excel ctitle(Neutral) stats(coef se) dec(3) append
*Diff-in-diff Choice vs Baseline:
lincom (_b[1.post#1.owned] + _b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment])
*Diff-in-diff Ownership vs Baseline:
lincom (_b[1.post#2.treatment] + _b[1.post#1.owned])
*Diff-in-diff Choice vs Ownership:
lincom (_b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment] - (_b[1.post#2.treatment]))
restore

*ONLY LOSERS (ZOOM, ALIBABA)
preserve
keep if stockgroup==1
*sum predprob if post==0
reghdfe predprob i.owned##i.post##i.treatment, absorb(stock#day idstock) cluster(id)
outreg2 using Reg_online2, stnum(replace coef=coef) adjr2 excel ctitle(Losers) stats(coef se) dec(3) append
*Diff-in-diff Choice vs Baseline:
lincom (_b[1.post#1.owned] + _b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment])
*Diff-in-diff Ownership vs Baseline:
lincom (_b[1.post#2.treatment] + _b[1.post#1.owned])
*Diff-in-diff Choice vs Ownership:
lincom (_b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment] - (_b[1.post#2.treatment]))
restore

*****************************************************************************************************************************
*******************************   Table E.6 in the Internet Appendix: Heterogeneity   ***************************************
*****************************************************************************************************************************

*****************************************************************************************************************************
*************************************          PANEL 1: High FLT vs. Low FLT            *************************************
*****************************************************************************************************************************
gen high_fin = .
replace high_fin = 1 if finlit==3
replace high_fin = 0 if finlit<2

*HIGH FLT

*All:
preserve
keep if high_fin==1
replace pred_norm = 100*pred_norm
reghdfe pred_norm i.post##i.treatment##i.owned, absorb(stock#day idstock) cluster(id)
**outreg2 using Reg_online, adjr2 excel ctitle(All) stats(coef se) dec(3) append
*Diff-in-diff Choice vs Baseline:
lincom (_b[1.post#1.owned] + _b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment])
*Diff-in-diff Ownership vs Baseline:
lincom (_b[1.post#2.treatment] + _b[1.post#1.owned])
*Diff-in-diff Choice vs Ownership:
lincom (_b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment] - (_b[1.post#2.treatment]))
restore

*Winners:
preserve
keep if high_fin==1
keep if stockgroup==3
replace pred_norm = 100*pred_norm
reghdfe pred_norm i.post##i.treatment##i.owned, absorb(stock#day idstock) cluster(id)
**outreg2 using Reg_online, adjr2 excel ctitle(Winners) stats(coef se) dec(3) replace
*Diff-in-diff Choice vs Baseline:
lincom (_b[1.post#1.owned] + _b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment])
*Diff-in-diff Ownership vs Baseline:
lincom (_b[1.post#2.treatment] + _b[1.post#1.owned])
*Diff-in-diff Choice vs Ownership:
lincom (_b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment] - (_b[1.post#2.treatment]))
restore

*Neutral:
preserve
keep if high_fin==1
keep if stockgroup==2
replace pred_norm = 100*pred_norm
reghdfe pred_norm i.post##i.treatment##i.owned, absorb(stock#day idstock) cluster(id)
**outreg2 using Reg_online, adjr2 excel ctitle(Neutral) stats(coef se) dec(3) append
*Diff-in-diff Choice vs Baseline:
lincom (_b[1.post#1.owned] + _b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment])
*Diff-in-diff Ownership vs Baseline:
lincom (_b[1.post#2.treatment] + _b[1.post#1.owned])
*Diff-in-diff Choice vs Ownership:
lincom (_b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment] - (_b[1.post#2.treatment]))
restore

*Losers:
preserve
keep if high_fin==1
keep if stockgroup==1
replace pred_norm = 100*pred_norm
reghdfe pred_norm i.post##i.treatment##i.owned, absorb(stock#day idstock) cluster(id)
**outreg2 using Reg_online, stnum(replace coef=100*coef) adjr2 excel ctitle(Losers) stats(coef se) dec(3) append
*Diff-in-diff Choice vs Baseline:
lincom (_b[1.post#1.owned] + _b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment])
*Diff-in-diff Ownership vs Baseline:
lincom (_b[1.post#2.treatment] + _b[1.post#1.owned])
*Diff-in-diff Choice vs Ownership:
lincom (_b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment] - (_b[1.post#2.treatment]))
restore

************************************

*LOW FLT

*All:
preserve
keep if high_fin==0
replace pred_norm = 100*pred_norm
reghdfe pred_norm i.post##i.treatment##i.owned, absorb(stock#day idstock) cluster(id)
**outreg2 using Reg_online, adjr2 excel ctitle(All) stats(coef se) dec(3) append
*Diff-in-diff Choice vs Baseline:
lincom (_b[1.post#1.owned] + _b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment])
*Diff-in-diff Ownership vs Baseline:
lincom (_b[1.post#2.treatment] + _b[1.post#1.owned])
*Diff-in-diff Choice vs Ownership:
lincom (_b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment] - (_b[1.post#2.treatment]))
restore

*Winners:
preserve
keep if high_fin==0
keep if stockgroup==3
replace pred_norm = 100*pred_norm
reghdfe pred_norm i.post##i.treatment##i.owned, absorb(stock#day idstock) cluster(id)
**outreg2 using Reg_online, adjr2 excel ctitle(Winners) stats(coef se) dec(3) append
*Diff-in-diff Choice vs Baseline:
lincom (_b[1.post#1.owned] + _b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment])
*Diff-in-diff Ownership vs Baseline:
lincom (_b[1.post#2.treatment] + _b[1.post#1.owned])
*Diff-in-diff Choice vs Ownership:
lincom (_b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment] - (_b[1.post#2.treatment]))
restore

*Neutral:
preserve
keep if high_fin==0
keep if stockgroup==2
replace pred_norm = 100*pred_norm
reghdfe pred_norm i.post##i.treatment##i.owned, absorb(stock#day idstock) cluster(id)
**outreg2 using Reg_online, adjr2 excel ctitle(Neutral) stats(coef se) dec(3) append
*Diff-in-diff Choice vs Baseline:
lincom (_b[1.post#1.owned] + _b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment])
*Diff-in-diff Ownership vs Baseline:
lincom (_b[1.post#2.treatment] + _b[1.post#1.owned])
*Diff-in-diff Choice vs Ownership:
lincom (_b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment] - (_b[1.post#2.treatment]))
restore

*Losers:
preserve
keep if high_fin==0
keep if stockgroup==1
replace pred_norm = 100*pred_norm
reghdfe pred_norm i.post##i.treatment##i.owned, absorb(stock#day idstock) cluster(id)
**outreg2 using Reg_online, adjr2 excel ctitle(Losers) stats(coef se) dec(3) append
*Diff-in-diff Choice vs Baseline:
lincom (_b[1.post#1.owned] + _b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment])
*Diff-in-diff Ownership vs Baseline:
lincom (_b[1.post#2.treatment] + _b[1.post#1.owned])
*Diff-in-diff Choice vs Ownership:
lincom (_b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment] - (_b[1.post#2.treatment]))
restore

*****************************************************************************************************************************
************************                     PANEL 2: By prior market experience            *********************************
*****************************************************************************************************************************

*EXPERIENCED SUBJECTS

*All:
preserve
keep if experienced==1
replace pred_norm = 100*pred_norm
reghdfe pred_norm i.post##i.treatment##i.owned, absorb(stock#day idstock) cluster(id)
*outreg2 using Reg_EXP, stnum(replace coef=*coef) adjr2 excel ctitle(All) stats(coef se) dec(3) append
*Diff-in-diff Choice vs Baseline:
lincom (_b[1.post#1.owned] + _b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment])
*Diff-in-diff Ownership vs Baseline:
lincom (_b[1.post#2.treatment] + _b[1.post#1.owned])
*Diff-in-diff Choice vs Ownership:
lincom (_b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment] - (_b[1.post#2.treatment]))
restore

*Winners:
preserve
keep if experienced==1
keep if stockgroup==3
replace pred_norm = 100*pred_norm
reghdfe pred_norm i.post##i.treatment##i.owned, absorb(stock#day idstock) cluster(id)
*outreg2 using Reg_EXP, stnum(replace coef=*coef) adjr2 excel ctitle(Winners) stats(coef se) dec(3) replace
*Diff-in-diff Choice vs Baseline:
lincom (_b[1.post#1.owned] + _b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment])
*Diff-in-diff Ownership vs Baseline:
lincom (_b[1.post#2.treatment] + _b[1.post#1.owned])
*Diff-in-diff Choice vs Ownership:
lincom (_b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment] - (_b[1.post#2.treatment]))
restore

*Neutral:
preserve
keep if experienced==1
keep if stockgroup==2
replace pred_norm = 100*pred_norm
reghdfe pred_norm i.post##i.treatment##i.owned, absorb(stock#day idstock) cluster(id)
*outreg2 using Reg_EXP, stnum(replace coef=*coef) adjr2 excel ctitle(Neutral) stats(coef se) dec(3) append
*Diff-in-diff Choice vs Baseline:
lincom (_b[1.post#1.owned] + _b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment])
*Diff-in-diff Ownership vs Baseline:
lincom (_b[1.post#2.treatment] + _b[1.post#1.owned])
*Diff-in-diff Choice vs Ownership:
lincom (_b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment] - (_b[1.post#2.treatment]))
restore

*Losers:
preserve
keep if experienced==1
keep if stockgroup==1
replace pred_norm = 100*pred_norm
reghdfe pred_norm i.post##i.treatment##i.owned, absorb(stock#day idstock) cluster(id)
*outreg2 using Reg_EXP, stnum(replace coef=*coef) adjr2 excel ctitle(Losers) stats(coef se) dec(3) append
*Diff-in-diff Choice vs Baseline:
lincom (_b[1.post#1.owned] + _b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment])
*Diff-in-diff Ownership vs Baseline:
lincom (_b[1.post#2.treatment] + _b[1.post#1.owned])
*Diff-in-diff Choice vs Ownership:
lincom (_b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment] - (_b[1.post#2.treatment]))
restore

*INEXPERIENCED SUBJECTS

*All:
preserve
keep if experienced==0
replace pred_norm = 100*pred_norm
reghdfe pred_norm i.post##i.treatment##i.owned, absorb(stock#day idstock) cluster(id)
*outreg2 using Reg_EXP, stnum(replace coef=*coef) adjr2 excel ctitle(All) stats(coef se) dec(3) append
*Diff-in-diff Choice vs Baseline:
lincom (_b[1.post#1.owned] + _b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment])
*Diff-in-diff Ownership vs Baseline:
lincom (_b[1.post#2.treatment] + _b[1.post#1.owned])
*Diff-in-diff Choice vs Ownership:
lincom (_b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment] - (_b[1.post#2.treatment]))
restore

*Winners:
preserve
keep if experienced==0
keep if stockgroup==3
replace pred_norm = 100*pred_norm
reghdfe pred_norm i.post##i.treatment##i.owned, absorb(stock#day idstock) cluster(id)
*outreg2 using Reg_EXP, stnum(replace coef=*coef) adjr2 excel ctitle(Winners) stats(coef se) dec(3) append
*Diff-in-diff Choice vs Baseline:
lincom (_b[1.post#1.owned] + _b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment])
*Diff-in-diff Ownership vs Baseline:
lincom (_b[1.post#2.treatment] + _b[1.post#1.owned])
*Diff-in-diff Choice vs Ownership:
lincom (_b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment] - (_b[1.post#2.treatment]))
restore

*Neutral:
preserve
keep if experienced==0
keep if stockgroup==2
replace pred_norm = 100*pred_norm
reghdfe pred_norm i.post##i.treatment##i.owned, absorb(stock#day idstock) cluster(id)
*outreg2 using Reg_EXP, stnum(replace coef=*coef) adjr2 excel ctitle(Neutral) stats(coef se) dec(3) append
*Diff-in-diff Choice vs Baseline:
lincom (_b[1.post#1.owned] + _b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment])
*Diff-in-diff Ownership vs Baseline:
lincom (_b[1.post#2.treatment] + _b[1.post#1.owned])
*Diff-in-diff Choice vs Ownership:
lincom (_b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment] - (_b[1.post#2.treatment]))
restore

*Losers:
preserve
keep if experienced==0
keep if stockgroup==1
replace pred_norm = 100*pred_norm
reghdfe pred_norm i.post##i.treatment##i.owned, absorb(stock#day idstock) cluster(id)
*outreg2 using Reg_EXP, stnum(replace coef=*coef) adjr2 excel ctitle(Losers) stats(coef se) dec(3) append
*Diff-in-diff Choice vs Baseline:
lincom (_b[1.post#1.owned] + _b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment])
*Diff-in-diff Ownership vs Baseline:
lincom (_b[1.post#2.treatment] + _b[1.post#1.owned])
*Diff-in-diff Choice vs Ownership:
lincom (_b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment] - (_b[1.post#2.treatment]))
restore

*****************************************************************************************************************************
************************                  PANEL 3: Likely vs. Unlikely to invest            *********************************
*****************************************************************************************************************************

*LIKELY TO INVEST IN THE FUTURE

*All:
preserve
keep if will_invest==1
replace pred_norm = 100*pred_norm
reghdfe pred_norm i.post##i.treatment##i.owned, absorb(stock#day idstock) cluster(id)
**outreg2 using Reg_online, stnum(replace coef=*coef) adjr2 excel ctitle(All) stats(coef se) dec(3) append
*Diff-in-diff Choice vs Baseline:
lincom (_b[1.post#1.owned] + _b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment])
*Diff-in-diff Ownership vs Baseline:
lincom (_b[1.post#2.treatment] + _b[1.post#1.owned])
*Diff-in-diff Choice vs Ownership:
lincom (_b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment] - (_b[1.post#2.treatment]))
restore

*Winners:
preserve
keep if will_invest==1
keep if stockgroup==3
replace pred_norm = 100*pred_norm
reghdfe pred_norm i.post##i.treatment##i.owned, absorb(stock#day idstock) cluster(id)
**outreg2 using Reg_online, stnum(replace coef=*coef) adjr2 excel ctitle(Winners) stats(coef se) dec(3) replace
*Diff-in-diff Choice vs Baseline:
lincom (_b[1.post#1.owned] + _b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment])
*Diff-in-diff Ownership vs Baseline:
lincom (_b[1.post#2.treatment] + _b[1.post#1.owned])
*Diff-in-diff Choice vs Ownership:
lincom (_b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment] - (_b[1.post#2.treatment]))
restore

*Neutral:
preserve
keep if will_invest==1
keep if stockgroup==2
replace pred_norm = 100*pred_norm
reghdfe pred_norm i.post##i.treatment##i.owned, absorb(stock#day idstock) cluster(id)
**outreg2 using Reg_online, stnum(replace coef=*coef) adjr2 excel ctitle(Neutral) stats(coef se) dec(3) append
*Diff-in-diff Choice vs Baseline:
lincom (_b[1.post#1.owned] + _b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment])
*Diff-in-diff Ownership vs Baseline:
lincom (_b[1.post#2.treatment] + _b[1.post#1.owned])
*Diff-in-diff Choice vs Ownership:
lincom (_b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment] - (_b[1.post#2.treatment]))
restore

*Losers:
preserve
keep if will_invest==1
keep if stockgroup==1
replace pred_norm = 100*pred_norm
reghdfe pred_norm i.post##i.treatment##i.owned, absorb(stock#day idstock) cluster(id)
**outreg2 using Reg_online, stnum(replace coef=*coef) adjr2 excel ctitle(Losers) stats(coef se) dec(3) append
*Diff-in-diff Choice vs Baseline:
lincom (_b[1.post#1.owned] + _b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment])
*Diff-in-diff Ownership vs Baseline:
lincom (_b[1.post#2.treatment] + _b[1.post#1.owned])
*Diff-in-diff Choice vs Ownership:
lincom (_b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment] - (_b[1.post#2.treatment]))
restore

************************************
*UNLIKELY TO INVEST IN THE FUTURE:

*All:
preserve
keep if will_invest==0
replace pred_norm = 100*pred_norm
reghdfe pred_norm i.post##i.treatment##i.owned, absorb(stock#day idstock) cluster(id)
**outreg2 using Reg_online, stnum(replace coef=*coef) adjr2 excel ctitle(All) stats(coef se) dec(3) append
*Diff-in-diff Choice vs Baseline:
lincom (_b[1.post#1.owned] + _b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment])
*Diff-in-diff Ownership vs Baseline:
lincom (_b[1.post#2.treatment] + _b[1.post#1.owned])
*Diff-in-diff Choice vs Ownership:
lincom (_b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment] - (_b[1.post#2.treatment]))
restore

*Winners:
preserve
keep if will_invest==0
keep if stockgroup==3
replace pred_norm = 100*pred_norm
reghdfe pred_norm i.post##i.treatment##i.owned, absorb(stock#day idstock) cluster(id)
**outreg2 using Reg_online, stnum(replace coef=*coef) adjr2 excel ctitle(Winners) stats(coef se) dec(3) append
*Diff-in-diff Choice vs Baseline:
lincom (_b[1.post#1.owned] + _b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment])
*Diff-in-diff Ownership vs Baseline:
lincom (_b[1.post#2.treatment] + _b[1.post#1.owned])
*Diff-in-diff Choice vs Ownership:
lincom (_b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment] - (_b[1.post#2.treatment]))
restore

*Neutral:
preserve
keep if will_invest==0
keep if stockgroup==2
replace pred_norm = 100*pred_norm
reghdfe pred_norm i.post##i.treatment##i.owned, absorb(stock#day idstock) cluster(id)
**outreg2 using Reg_online, stnum(replace coef=*coef) adjr2 excel ctitle(Neutral) stats(coef se) dec(3) append
*Diff-in-diff Choice vs Baseline:
lincom (_b[1.post#1.owned] + _b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment])
*Diff-in-diff Ownership vs Baseline:
lincom (_b[1.post#2.treatment] + _b[1.post#1.owned])
*Diff-in-diff Choice vs Ownership:
lincom (_b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment] - (_b[1.post#2.treatment]))
restore

*Losers:
preserve
keep if will_invest==0
keep if stockgroup==1
replace pred_norm = 100*pred_norm
reghdfe pred_norm i.post##i.treatment##i.owned, absorb(stock#day idstock) cluster(id)
**outreg2 using Reg_online, stnum(replace coef=*coef) adjr2 excel ctitle(Losers) stats(coef se) dec(3) append
*Diff-in-diff Choice vs Baseline:
lincom (_b[1.post#1.owned] + _b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment])
*Diff-in-diff Ownership vs Baseline:
lincom (_b[1.post#2.treatment] + _b[1.post#1.owned])
*Diff-in-diff Choice vs Ownership:
lincom (_b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment] - (_b[1.post#2.treatment]))
restore

*****************************************************************************************************************************
************************                  PANEL 4: Third/Fourth vs. First year students            **************************
*****************************************************************************************************************************

*3RD & 4TH YEAR STUDENTS:

*All:
preserve
keep if expert==1
replace pred_norm = 100*pred_norm
reghdfe pred_norm i.post##i.treatment##i.owned, absorb(stock#day idstock) cluster(id)
**outreg2 using Reg_online, stnum(replace coef=*coef) adjr2 excel ctitle(All) stats(coef se) dec(3) append
*Diff-in-diff Choice vs Baseline:
lincom (_b[1.post#1.owned] + _b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment])
*Diff-in-diff Ownership vs Baseline:
lincom (_b[1.post#2.treatment] + _b[1.post#1.owned])
*Diff-in-diff Choice vs Ownership:
lincom (_b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment] - (_b[1.post#2.treatment]))
restore

*Winners:
preserve
keep if expert==1
keep if stockgroup==3
replace pred_norm = 100*pred_norm
reghdfe pred_norm i.post##i.treatment##i.owned, absorb(stock#day idstock) cluster(id)
**outreg2 using Reg_online, stnum(replace coef=*coef) adjr2 excel ctitle(Winners) stats(coef se) dec(3) replace
*Diff-in-diff Choice vs Baseline:
lincom (_b[1.post#1.owned] + _b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment])
*Diff-in-diff Ownership vs Baseline:
lincom (_b[1.post#2.treatment] + _b[1.post#1.owned])
*Diff-in-diff Choice vs Ownership:
lincom (_b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment] - (_b[1.post#2.treatment]))
restore

*Neutral:
preserve
keep if expert==1
keep if stockgroup==2
replace pred_norm = 100*pred_norm
reghdfe pred_norm i.post##i.treatment##i.owned, absorb(stock#day idstock) cluster(id)
**outreg2 using Reg_online, stnum(replace coef=*coef) adjr2 excel ctitle(Neutral) stats(coef se) dec(3) append
*Diff-in-diff Choice vs Baseline:
lincom (_b[1.post#1.owned] + _b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment])
*Diff-in-diff Ownership vs Baseline:
lincom (_b[1.post#2.treatment] + _b[1.post#1.owned])
*Diff-in-diff Choice vs Ownership:
lincom (_b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment] - (_b[1.post#2.treatment]))
restore

*Losers:
preserve
keep if expert==1
keep if stockgroup==1
replace pred_norm = 100*pred_norm
reghdfe pred_norm i.post##i.treatment##i.owned, absorb(stock#day idstock) cluster(id)
**outreg2 using Reg_online, stnum(replace coef=*coef) adjr2 excel ctitle(Losers) stats(coef se) dec(3) append
*Diff-in-diff Choice vs Baseline:
lincom (_b[1.post#1.owned] + _b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment])
*Diff-in-diff Ownership vs Baseline:
lincom (_b[1.post#2.treatment] + _b[1.post#1.owned])
*Diff-in-diff Choice vs Ownership:
lincom (_b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment] - (_b[1.post#2.treatment]))
restore


*****************
*1ST YEAR STUDENTS

*All:
preserve
keep if expert==0
replace pred_norm = 100*pred_norm
reghdfe pred_norm i.post##i.treatment##i.owned, absorb(stock#day idstock) cluster(id)
**outreg2 using Reg_online, stnum(replace coef=*coef) adjr2 excel ctitle(All) stats(coef se) dec(3) append
*Diff-in-diff Choice vs Baseline:
lincom (_b[1.post#1.owned] + _b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment])
*Diff-in-diff Ownership vs Baseline:
lincom (_b[1.post#2.treatment] + _b[1.post#1.owned])
*Diff-in-diff Choice vs Ownership:
lincom (_b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment] - (_b[1.post#2.treatment]))
restore

*Winners:
preserve
keep if expert==0
keep if stockgroup==3
replace pred_norm = 100*pred_norm
reghdfe pred_norm i.post##i.treatment##i.owned, absorb(stock#day idstock) cluster(id)
**outreg2 using Reg_online, stnum(replace coef=*coef) adjr2 excel ctitle(Winners) stats(coef se) dec(3) append
*Diff-in-diff Choice vs Baseline:
lincom (_b[1.post#1.owned] + _b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment])
*Diff-in-diff Ownership vs Baseline:
lincom (_b[1.post#2.treatment] + _b[1.post#1.owned])
*Diff-in-diff Choice vs Ownership:
lincom (_b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment] - (_b[1.post#2.treatment]))
restore

*Neutral:
preserve
keep if expert==0
keep if stockgroup==2
replace pred_norm = 100*pred_norm
reghdfe pred_norm i.post##i.treatment##i.owned, absorb(stock#day idstock) cluster(id)
**outreg2 using Reg_online, stnum(replace coef=*coef) adjr2 excel ctitle(Neutral) stats(coef se) dec(3) append
*Diff-in-diff Choice vs Baseline:
lincom (_b[1.post#1.owned] + _b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment])
*Diff-in-diff Ownership vs Baseline:
lincom (_b[1.post#2.treatment] + _b[1.post#1.owned])
*Diff-in-diff Choice vs Ownership:
lincom (_b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment] - (_b[1.post#2.treatment]))
restore

*Losers:
preserve
keep if expert==0
keep if stockgroup==1
replace pred_norm = 100*pred_norm
reghdfe pred_norm i.post##i.treatment##i.owned, absorb(stock#day idstock) cluster(id)
**outreg2 using Reg_online, stnum(replace coef=*coef) adjr2 excel ctitle(Losers) stats(coef se) dec(3) append
*Diff-in-diff Choice vs Baseline:
lincom (_b[1.post#1.owned] + _b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment])
*Diff-in-diff Ownership vs Baseline:
lincom (_b[1.post#2.treatment] + _b[1.post#1.owned])
*Diff-in-diff Choice vs Ownership:
lincom (_b[1.post#1.treatment] + _b[1.owned#1.post#1.treatment] - (_b[1.post#2.treatment]))
restore


*****************************************************************************************************************************
*************************************      Table 6 in the main text: Disposition effect     **************************************************
*****************************************************************************************************************************

preserve
keep if day==42
drop if owned==0&treatment>0
*Drop subjects who did not complete the final stage
drop if screen_time_secs_portfolio==. & id!=1014
gen realized = sell if treatment>0
replace realized = 1-buy if treatment==0
collapse realized, by(id treatment stockgroup)
gen realized_loser = realized if stockgroup==1
gen realized_winner = realized if stockgroup==3
collapse realized_loser realized_winner, by(id treatment)
gen DE = realized_winner - realized_loser
bys treatment: ci mean DE
kwallis DE, by(treatment)
*B v C:
ranksum DE if treatment!=2, by(treatment)
*B v O:
ranksum DE if treatment!=1, by(treatment)
*O v C:
ranksum DE if treatment!=0, by(treatment)

*We test Baseline vs Choice & Ownership together
gen choice_ownership = 0
replace choice_ownership = 1 if (treatment == 1 | treatment == 2)
ranksum DE, by(choice_ownership)

restore

*****************************************************************************************************************************
*******************      Figure 5 in the main text: Proportions of stocks held at the end of each study    ******************
*****************************************************************************************************************************

*LEFT PANEL: Means

preserve
keep if day==42
drop if owned==0&treatment>0
*Drop subjects who did not complete the final stage
drop if screen_time_secs_portfolio==. & id!=1014
gen hold = 0 
replace hold = buy if treatment==0
replace hold = 1-sell if treatment>0
gen realized = sell if treatment>0
replace realized = 1-buy if treatment==0
collapse hold realized, by(id treatment stockgroup)
*O v C:
*ranksum DE if treatment>0, by(treatment)
bys stockgroup: ranksum hold if treatment>0, by(treatment)
*B v O:
*ranksum DE if treatment<2, by(treatment)
bys stockgroup: ranksum hold if (treatment==0|treatment==2), by(treatment)
*B v C:
*ranksum DE if treatment!=1, by(treatment)
bys stockgroup: ranksum hold if treatment<2, by(treatment)

collapse hold (semean) se = hold, by(treatment stockgroup)
gen hi = hold+se
gen lo = hold-se
grstyle init
grstyle set plain
gen x = 1 if stockgroup==3
replace x = 2 if stockgroup==2
replace x = 3 if stockgroup==1

twoway ///
	(rcap hi lo x if treatment==0, lc(green)) ///
	(rcap hi lo x if treatment==1, lc(cranberry)) ///
	(rcap hi lo x if treatment==2, lc(midblue)) ///
	(connected hold x if treatment==0, lc(green) mc(green) m(O)) ///
	(connected hold x if treatment==1, lc(cranberry) mc(cranberry) m(T)) ///
	(connected hold x if treatment==2, lc(midblue) mc(midblue) m(S)), ///
	xlabel(1 "Winners" 2 "Neutral" 3 "Losers")  ///		
	legend(rows(1) region(lwidth(none)) order(4 5 6) ///
	label(4 "Baseline") label(5 "Choose") label(6 "Ownership"))  ///
	xtitle("") scale(1) plotregion(margin(l=7 r=7)) ///
	subtitle("Means") name(hold_Study2, replace) graphregion(color(white))

restore

*RIGHT PANEL: Margins (Only target stocks)

preserve
keep if day==42
drop if owned==0&treatment>0
*Drop subjects who did not complete the final stage
drop if screen_time_secs_portfolio==. & id!=1014
gen hold = 0 
replace hold = buy if treatment==0
replace hold = 1-sell if treatment>0

keep if target==1

regress hold pred_norm predprob i.treatment##i.stockgroup, cluster(id)

test _b[0bn.treatment#1bn.stockgroup] = _b[1.treatment#1bn.stockgroup]
test _b[0bn.treatment#3.stockgroup] = _b[1.treatment#3.stockgroup]

*DE in Choice vs DE in Baseline:
test _b[0bn.treatment#3.stockgroup] - _b[0bn.treatment#1bn.stockgroup] = _b[1.treatment#3.stockgroup] - _b[1.treatment#1bn.stockgroup]
margins treatment#stockgroup, saving(fig5margins, replace)
clear 
use fig5margins
rename (_margin _se _m1 _m2) (hold se treatment stockgroup)
gen hi = hold+se
gen lo = hold-se
gen x = 1 if stockgroup==3
replace x = 2 if stockgroup==2
replace x = 3 if stockgroup==1

twoway ///
(rcap hi lo x if treatment==0, lc(green)) ///
(rcap hi lo x if treatment==1, lc(cranberry)) ///
(rcap hi lo x if treatment==2, lc(midblue)) ///
(connected hold x if treatment==0, lc(green) mc(green) m(O)) ///
(connected hold x if treatment==1, lc(cranberry) mc(cranberry) m(T)) ///
(connected hold x if treatment==2, lc(midblue) mc(midblue) m(S)) ///
, xlabel(1 "Winners" 2 "Neutral" 3 "Losers")  ///
legend(size(*.8) rows(1) region(lwidth(none)) order(4 5 6) ///
label(4 "Baseline") label(5 "Choice") label(6 "Ownership")) ///
xtitle("") scale(1) plotregion(margin(medium)) graphregion(color(white)) ///
subtitle("Margins") name(hold_Marginsplot2, replace)

restore

grc1leg hold_Study2 hold_Marginsplot2, legendfrom(hold_Marginsplot2) rows(1) ///
title("Study 2", size(*.8)) imargin(r=6 l=6) ycommon scale(1.3) name(Fig5_2_new, replace)

graph save Fig5_2_new.gph, replace

grc1leg2 Fig5_1_new.gph Fig5_2_new.gph, graphregion(margin(zero)) imargin(l=2 r=2) ///
legendfrom(Fig5_1_new.gph) ysize(5) row(2) graphregion(color(white)) scale(1.0) name(hold_combined2, replace)



****************************************************************************************************
****************  TABLE E9 IN THE APPENDIX: MEDIATION ANALYSIS  ************************************
****************************************************************************************************

preserve
*Keep only target stocks (to ensure that t_choose is exogenous)
keep if target==1
*Drop subjects who did not complete the final stage
drop if screen_time_secs_portfolio==. & id!=1014
keep if day==42
drop if owned==0&treatment>0
drop if treatment==2
gen hold = 0 
replace hold = buy if treatment==0
replace hold = 1-sell if treatment>0
gen t_choose = treatment==1
gen facebook = stock==2
gen netflix = stock==3
gen tesla = stock==4
gen uber = stock==5
gen zoom = stock==6

*All:
medeff (regress pred_norm t_choose facebook netflix tesla uber zoom) ///
(regress hold pred_norm t_choose facebook netflix tesla uber zoom) ///
, mediate(pred_norm) treat(t_choose) vce(cluster id)
outreg2 using Reg_med, stnum(replace coef=100*coef) adjr2 excel ctitle(All) stats(coef se) dec(3) replace

*Winners:
medeff (regress pred_norm t_choose uber) ///
(regress hold pred_norm t_choose uber) if stockgroup==3 ///
, mediate(pred_norm) treat(t_choose) vce(cluster id)
outreg2 using Reg_med, stnum(replace coef=100*coef) adjr2 excel ctitle(Winners) stats(coef se) dec(3) append

*Neutral:
medeff (regress pred_norm t_choose netflix) ///
(regress hold pred_norm t_choose netflix) if stockgroup==2 ///
, mediate(pred_norm) treat(t_choose) vce(cluster id)
outreg2 using Reg_med, stnum(replace coef=100*coef) adjr2 excel ctitle(Neutral) stats(coef se) dec(3) append

*Losers:
medeff (regress pred_norm t_choose zoom) ///
(regress hold pred_norm t_choose zoom) if stockgroup==1 ///
, mediate(pred_norm) treat(t_choose) vce(cluster id)
outreg2 using Reg_med, stnum(replace coef=100*coef) adjr2 excel ctitle(Losers) stats(coef se) dec(3) append

restore


******************************************************************************************************************
****************************       TABLE E10 IN THE APPENDIX: MEDIATION ANALYSIS IN STUDY 2     ******************
****************************                 ACCOUNTING FOR MEASUREMENT ERROR                   ******************
******************************************************************************************************************

*****************************************************************************************************************************
*PANEL A: Principal components
*****************************************************************************************************************************
preserve

gen predmid = (predmin + predmax)/2
gen predmidnorm = (predmid - price)/price
gen predamp = (predmax - predmin)/predmid
gen predminnorm = (predmin - price)/price
gen predmaxnorm = (predmax - price)/price

*NEW: Keep only target stocks (to ensure that t_choose is exogenous)
keep if target==1
*Drop subjects who did not complete the final stage
drop if screen_time_secs_portfolio==. & id!=1014
keep if day==42
drop if owned==0&treatment>0
drop if treatment==2
gen hold = 0 
replace hold = buy if treatment==0
replace hold = 1-sell if treatment>0
gen t_choose = treatment==1
gen facebook = stock==2
gen netflix = stock==3
gen tesla = stock==4
gen uber = stock==5
gen zoom = stock==6
******************
*Standardize variables:
foreach var of varlist pred_norm predprob predmidnorm predminnorm predmaxnorm {
	egen std`var'=std(`var')
}
rename stdpred_norm stdprednorm
pca stdprednorm stdpredprob stdpredminnorm stdpredmaxnorm
predict pc1
******************************************************

*All:
medeff (regress pc1 t_choose facebook netflix tesla uber zoom) ///
(regress hold pc1 t_choose facebook netflix tesla uber zoom) ///
, mediate(pc1) treat(t_choose) vce(cluster id)

*Winners:
medeff (regress pc1 t_choose uber) ///
(regress hold pc1 t_choose uber) if stockgroup==3 ///
, mediate(pc1) treat(t_choose) vce(cluster id)

*Neutral:
medeff (regress pc1 t_choose netflix) ///
(regress hold pc1 t_choose netflix) if stockgroup==2 ///
, mediate(pc1) treat(t_choose) vce(cluster id)

*Losers:
medeff (regress pc1 t_choose zoom) ///
(regress hold pc1 t_choose zoom) if stockgroup==1 ///
, mediate(pc1) treat(t_choose) vce(cluster id)
*outreg2 using Reg_med, stnum(replace coef=100*coef) adjr2 excel ctitle(Losers) stats(coef) dec(3) append


*****************************************************************************************************************************
*PANEL B: GMM-ORIV Estimation
*****************************************************************************************************************************

*Generate 2 stacked copies of the data:
expand 2, gen(replicant)
*Generate dep var and instruments:
gen mainVar =  stdprednorm if replicant == 0
replace mainVar = stdpredmidnorm if replicant == 1
gen instrument = stdpredmidnorm if replicant == 0
replace instrument = stdprednorm if replicant == 1

*All:
gmm	(eq1: hold-{xb: mainVar t_choose facebook netflix tesla uber zoom}-{b0})  ///
	(eq2: mainVar-{xc: t_choose facebook netflix tesla uber zoom}-{c0}),  ///
	instruments(eq1: t_choose facebook netflix tesla uber zoom instrument)   ///
	instruments(eq2: t_choose facebook netflix tesla uber zoom)    ///
	winitial(unadjusted, independent) wmatrix(cluster id)
*Acme
nlcom _b[xb:mainVar]*_b[xc:t_choose]
*Direct
nlcom _b[xb:t_choose]
*Total
nlcom _b[xb:mainVar]*_b[xc:t_choose] + _b[xb:t_choose]
*Mediated effect
nlcom (_b[xb:mainVar]*_b[xc:t_choose])/(_b[xb:mainVar]*_b[xc:t_choose] + _b[xb:t_choose])


*Winners:
gmm	(eq1: hold-{xb: mainVar t_choose uber}-{b0})  ///
	(eq2: mainVar-{xc: t_choose uber}-{c0}) if stockgroup==3,  ///
	instruments(eq1: t_choose uber instrument)   ///
	instruments(eq2: t_choose uber)    ///
	winitial(unadjusted, independent) wmatrix(cluster id)
*Acme
nlcom _b[xb:mainVar]*_b[xc:t_choose]
*Direct
nlcom _b[xb:t_choose]
*Total
nlcom _b[xb:mainVar]*_b[xc:t_choose] + _b[xb:t_choose]
*Mediated effect
nlcom (_b[xb:mainVar]*_b[xc:t_choose])/(_b[xb:mainVar]*_b[xc:t_choose] + _b[xb:t_choose])

*Neutral:
gmm	(eq1: hold-{xb: mainVar t_choose netflix}-{b0})  ///
	(eq2: mainVar-{xc: t_choose netflix}-{c0}) if stockgroup==2,  ///
	instruments(eq1: t_choose netflix instrument)   ///
	instruments(eq2: t_choose netflix)    ///
	winitial(unadjusted, independent) wmatrix(cluster id)
*Acme
nlcom _b[xb:mainVar]*_b[xc:t_choose]
*Direct
nlcom _b[xb:t_choose]
*Total
nlcom _b[xb:mainVar]*_b[xc:t_choose] + _b[xb:t_choose]
*Mediated effect
nlcom (_b[xb:mainVar]*_b[xc:t_choose])/(_b[xb:mainVar]*_b[xc:t_choose] + _b[xb:t_choose])

*Losers:
gmm	(eq1: hold-{xb: mainVar t_choose zoom}-{b0})  ///
	(eq2: mainVar-{xc: t_choose zoom}-{c0}) if stockgroup==1,  ///
	instruments(eq1: t_choose zoom instrument)   ///
	instruments(eq2: t_choose zoom)    ///
	winitial(unadjusted, independent) wmatrix(cluster id)
*Acme
nlcom _b[xb:mainVar]*_b[xc:t_choose]
*Direct
nlcom _b[xb:t_choose]
*Total
nlcom _b[xb:mainVar]*_b[xc:t_choose] + _b[xb:t_choose]
*Mediated effect
nlcom (_b[xb:mainVar]*_b[xc:t_choose])/(_b[xb:mainVar]*_b[xc:t_choose] + _b[xb:t_choose])


*bys replicant: ivregress 2sls hold (mainVar = instrument) t_choose zoom if stockgroup==1, vce(cluster id)

restore

*****************************************************************************************************************************
****************************************         ONLINE APPENDIX                    *****************************************
*****************************************************************************************************************************

*****************************************************************************************************************************
******************         FIGURE D.1: Mean predictions about target stocks by period       **********************************
*****************************************************************************************************************************

preserve

collapse predprice treatment, by(day id)

gen makes = .
replace makes = 1 if predprice!=.
replace makes = 0 if predprice==.

egen sum=sum(makes), by(treatment day)

gen perc_makes = 100*sum/286
replace perc_makes = 100*sum/286 if treatment==1
replace perc_makes = 100*sum/278 if treatment==2

drop if perc_makes==0

sort treatment day

twoway ///
(connected perc_makes day if treatment==0, lc(green) mc(green) m(O)) ///
(connected perc_makes day if treatment==1, lc(cranberry) mc(cranberry) m(T)) ///
(connected perc_makes day if treatment==2, lc(midblue) mc(midblue) m(S)), ///
xline(21, lpattern(dash) lcolor(black)) ///
legend(rows(1) region(lwidth(none)) order(1 2 3) ///
label(1 "Baseline") label(2 "Choice") label(3 "Ownership")) ///
xtitle("Days") yscale(range(0 100)) ylabel(0 (20) 100) ytitle("Predictions made (%)") scale(1) plotregion(margin(sides)) ///
graphregion(color(white)) title("") name(Fig_D1, replace)

graph save Fig_D1, replace


restore

*************************************************  	ENDS HERE  ***********************************************************
